0
我想在這裏重新寫這個URL;htaccess mod_rewrite URL問題
site.com/product.php?s=electricity-at-work-regulations
到
site.com/courses/electricity-at-work-regulations
所以更改product.php到課程和一般整齊的URL設置。
這可能嗎?
.htacess文件
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^peoplefactor.co.uk$ [NC]
RewriteRule ^(.*)$ http://peoplefactor.co.uk/$1 [L,R=301]
</IfModule>
# Clean URLS
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteRule ^blog/([a-zA-Z0-9-/]+)/preview$ /blog/post.php?s=$1&preview=all [L]
RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]
RewriteRule ^course/([a-zA-Z0-9-/]+)$ /course.php?s=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
</IfModule>
# Gets rid of www.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule^http://%1%{REQUEST_URI} [R=301,L]
</IfModule>
完美,謝謝。 正如您所建議的,我會在應用程序中將其更改爲「課程」。你會碰巧知道清理這個網址的最好方法嗎? 'site.com/courses.php?S =電力-AT-工作regulations' 閱讀 'site.com /場/電-AT-工作regulations'再次 感謝。 – Cameron
從頭開始,應該看起來像RewriteRule ^(courses.php \?s \ =)/([a-zA-Z \ - ] +)$ courses/$ 2 [L]無法測試它 – Eric
這似乎適用於我, '重寫規則^ course /([a-zA-Z0-9 - /] +)$ /course.php?s=$1 [L]'但現在我的css或js文件都不是加工。這很奇怪,因爲當我查看源代碼鏈接時,開發人員工具中沒有錯誤。有任何想法嗎? – Cameron