htaccess从子目录重定向到子目录

时间:2012-04-03 10:03:07

标签: .htaccess rewrite

我正在尝试在“/”目录中设置在服务器中工作的php站点的本地实例。我的本地实例将在我的开发环境中的“/ subdirectory /".

中工作

我正在尝试翻译 .htaccess 以适应这一点,但我总是得到404.这是原始 .htaccess

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule  ^my-nice-url$ /index.php?p=ugly_url

这些是我的尝试:

RewriteEngine on
RewriteBase /mylocaldirectory/

# Not in local! RewriteCond %{HTTP_HOST} ^example.com$ [NC]
# Not in local! RewriteRule ^(.*)$ http://www.example.com/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule  ^my-nice-url$ /index.php?p=ugly_url

另外

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule  ^(.*)my-nice-url$ /index.php?p=ugly_url

谢谢

1 个答案:

答案 0 :(得分:0)

如果我说得对,你想要一个用户友好的网址,我这样做:

RewriteRule ^(.*)/(your-nice-url)$  ($1)/$2/ [R=301]
RewriteRule ^(.*)/(your-nice-url)/$ $1/index.php?p=$2 [L]

RewriteRule ^(.*)/(your-nice-url)$  ($1)/$2/ [R=301]
RewriteRule ^(.*)/(your-nice-url)/$ $1/index.php?p=what-ever-you-need [L]

希望对你有所帮助。