问题描述:

I was wondering how in .htaccess I can redirect the following URL:

/mysite.com/blog/Something => /mysite.com/blog.php?tag=Something

Here is a script I've used on a different site however this is a bit simpilar:

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteRule ^([a-zA-Z0-9]+)$ index.php?name=$1

RewriteRule ^([a-zA-Z0-9]+)/$ index.php?name=$1

</IfModule>

Thanks in Advance

网友答案:

Just add this rule:

RewriteRule ^blog/(.*)$ blog.php?tag=$1 [L,QSA,NC]

Update: As per your comment this is the rule you will need:

RewriteRule ^blog/([^/]*) blog.php?tag=$1 [L,QSA,NC]
网友答案:

Try adding the following to the .htaccess file in the root directory of your site.

RewriteEngine on
RewriteBase / 

#/mysite.com/blog/Something to /mysite.com/blog.php?tag=Something
RewriteRule ^blog/(something)$ blog.php?tag=$1 [L,NC,R=301] 

If something is a variable then change the rule to

RewriteRule ^blog/(\w+)$ blog.php?tag=$1 [L,NC,R=301] 

If you want the URL to stay the same in the Users browser then drop the R=301 as below

RewriteRule ^blog/(\w+)$ blog.php?tag=$1 [L,NC] 
相关阅读:
Top