2015-10-05 103 views
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> 

回答

1

是的,但它会更好,周围的其他方法。 您应该始终在您的应用程序中调用site.com/courses/electricity-at-work-regulations并将其重新路由到site.com/product.php?s=electricity-at-work-regulations。类似于

RewriteEngine On 
RewriteBase/
RewriteRule ^(courses)/([a-zA-Z\-]+)$ product.php?s=$2 [L] 
+0

完美,谢谢。 正如您所建议的,我会在应用程序中将其更改为“课程”。你会碰巧知道清理这个网址的最好方法吗? 'site.com/courses.php?S =电力-AT-工作regulations' 阅读 'site.com /场/电-AT-工作regulations'再次 感谢。 – Cameron

+0

从头开始,应该看起来像RewriteRule ^(courses.php \?s \ =)/([a-zA-Z \ - ] +)$ courses/$ 2 [L]无法测试它 – Eric

+0

这似乎适用于我, '重写规则^ course /([a-zA-Z0-9 - /] +)$ /course.php?s=$1 [L]'但现在我的css或js文件都不是加工。这很奇怪,因为当我查看源代码链接时,开发人员工具中没有错误。有任何想法吗? – Cameron