2015-10-20 94 views
2

我已经创建了一个子域来指向我的根目录中的一个文件夹,像这样;子域中子文件夹的htaccess规则

RewriteCond %{HTTP_HOST} ^blog\.example\.co.uk$ [NC] 
RewriteCond %{REQUEST_URI} !^/blog/ [NC] 
RewriteRule ^(.*)$ /blog/$1 [L] 

现在我可以访问/blog文件夹的文件,这样http://blog.example.co.uk/index.php

/blog文件夹中包含一个包含脚本的文件夹/php。 我无法像这样访问/php文件夹http://blog.example.co.uk/php/test.php

这不起作用。对于我访问他们,我必须这样做http://www.example.co.uk/blog/php/test.php

下面是我目前.htaccess

Options +FollowSymLinks -MultiViews 
### Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/
### Prevent rules on script folder in root /php & /blog/php because I remove .php extension from all files 
RewriteRule ^(php|blog/php)($|/) - [L] 
### To externally redirect /dir/foo.php to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1 [R,L,NC] 
### To internally redirect /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME}.php -f [NC] 
RewriteRule^%{REQUEST_URI}.php [L] 
### My subdomain 
RewriteCond %{HTTP_HOST} ^blog\.example\.co.uk$ [NC] 
RewriteCond %{REQUEST_URI} !^/blog/ [NC] 
RewriteRule ^(.*)$ /blog/$1 [L] 

现在我需要创建一个规则,使其指向http://blog.example.co.uk/php/blog/php

当我尝试访问文件/ php现在我收到文件未找到错误

谢谢

这是我完整的htaccess。漂亮的网址规则不起作用。

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

### Blog subdomain 
RewriteCond %{HTTP_HOST} ^blog\.example\.co.uk$ [NC] 
RewriteCond %{REQUEST_URI} !^/blog/ [NC] 
RewriteRule ^(.*)$ /blog/$1 [L] 

### Careers subdomain 
RewriteCond %{HTTP_HOST} ^careers\.example\.co.uk$ [NC] 
RewriteCond %{REQUEST_URI} !^/careers/ [NC] 
RewriteRule ^(.*)$ /careers/$1 [L] 

RewriteRule ^(php|blog/php|careers/php|vendors|blog/vendors)($|/) - [L] 

# To remove index.php or index.html from URL 
RewriteCond %{REQUEST_URI} /index\.html?$ [NC] 
RewriteRule ^(.*)index\.html?$ "/$1" [NC,R=301,NE,L] 
RewriteCond %{REQUEST_URI} /index\.php?$ [NC] 
RewriteRule ^(.*)index\.php?$ "/$1" [NC,R=301,NE,L] 

# To externally redirect /dir/foo.php to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1 [R=302,L] 

## To internally redirect /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME}.php -f [NC] 
RewriteRule ^(.+?)/?$ $1.php [L] 

# To externally redirect /dir/foo.html to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC] 
RewriteRule^%1 [R,L,NC] 

## To internally redirect /dir/foo to /dir/foo.html 
RewriteCond %{REQUEST_FILENAME}.html -f [NC] 
RewriteRule^%{REQUEST_URI}.html [L] 

# external redirect from actual URL to pretty one (BLOG) 
RewriteCond %{THE_REQUEST} \s/+post(?:\.php)?\?id=([^\s&]+)&title=([^\s&]+) [NC] 
RewriteRule^/post/%1/%2? [R=302,L,NE] 
RewriteCond %{THE_REQUEST} \s/+category(?:\.php)?\?id=([^\s&]+)&title=([^\s&]+) [NC] 
RewriteRule^/category/%1/%2? [R=302,L,NE] 
RewriteCond %{THE_REQUEST} \s/+author(?:\.php)?\?author=([^\s&]+) [NC] 
RewriteRule^/author/%1? [R=302,L,NE] 

# external redirect from actual URL to pretty one (CAREERS) 
RewriteCond %{THE_REQUEST} \s/+role(?:\.php)?\?id=([^\s&]+)&role=([^\s&]+) [NC] 
RewriteRule^/role/%1/%2? [R=302,L,NE] 

# internal forward from pretty URL to actual one (BLOG) 
RewriteRule ^post/([\w-]+)/([\w-]+)/?$ post.php?id=$1&title=%2 [L,QSA,NC] 
RewriteRule ^category/([\w-]+)/([\w-]+)/?$ category.php?id=$1&title=%2 [L,QSA,NC] 
RewriteRule ^author/([\w-]+)?$ author.php?author=$1 [L,QSA,NC] 

# internal forward from pretty URL to actual one (CAREERS) 
RewriteRule ^role/([\w-]+)/([\w-]+)/?$ role.php?id=$1&role=%2 [L,QSA,NC] 

### Error 404 redirect 
ErrorDocument 404 /404page.php 

回答

0

尝试下列规则:

### Error 404 redirect 
ErrorDocument 404 /404page.php 

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

# external redirect from actual URL to pretty one (BLOG) 
RewriteCond %{THE_REQUEST} \s/+post(?:\.php)?\?id=([^\s&]+)&title=([^\s&]+) [NC] 
RewriteRule^/post/%1/%2? [R=302,L,NE] 

RewriteCond %{THE_REQUEST} \s/+category(?:\.php)?\?id=([^\s&]+)&title=([^\s&]+) [NC] 
RewriteRule^/category/%1/%2? [R=302,L,NE] 

RewriteCond %{THE_REQUEST} \s/+author(?:\.php)?\?author=([^\s&]+) [NC] 
RewriteRule^/author/%1? [R=302,L,NE] 

# external redirect from actual URL to pretty one (CAREERS) 
RewriteCond %{THE_REQUEST} \s/+role(?:\.php)?\?id=([^\s&]+)&role=([^\s&]+) [NC] 
RewriteRule^/role/%1/%2? [R=302,L,NE] 

# To remove index.php or index.html from URL 
RewriteCond %{REQUEST_URI} /index\.html?$ [NC] 
RewriteRule ^(.*)index\.html?$ /$1 [NC,R=301,NE,L] 

RewriteCond %{REQUEST_URI} /index\.php$ [NC] 
RewriteRule ^(.*)index\.php?$ /$1 [NC,R=301,NE,L] 

# To externally redirect /dir/foo.php to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC] 
RewriteRule^%1 [R=302,L] 

# To externally redirect /dir/foo.html to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC] 
RewriteRule^%1 [R=302,L] 

# skip all files and directories from rewrite rules below 
RewriteCond %{REQUEST_FILENAME} -d [OR] 
RewriteCond %{REQUEST_FILENAME} -f 
RewriteRule^- [L] 

# internal forward from pretty URL to actual one (BLOG) 
RewriteRule ^post/([\w-]+)/([\w-]+)/?$ post.php?id=$1&title=$2 [L,QSA,NC] 

RewriteRule ^category/([\w-]+)/([\w-]+)/?$ category.php?id=$1&title=$2 [L,QSA,NC] 

RewriteRule ^author/([\w-]+)?$ author.php?author=$1 [L,QSA,NC] 

# internal forward from pretty URL to actual one (CAREERS) 
RewriteRule ^role/([\w-]+)/([\w-]+)/?$ role.php?id=$1&role=$2 [L,QSA,NC] 

### Blog subdomain 
RewriteCond %{HTTP_HOST} ^blog\.example\.co.uk$ [NC] 
RewriteCond %{REQUEST_URI} !^/blog/ [NC] 
RewriteRule ^(.*)$ blog/$1 [L] 

### Careers subdomain 
RewriteCond %{HTTP_HOST} ^careers\.example\.co.uk$ [NC] 
RewriteCond %{REQUEST_URI} !^/careers/ [NC] 
RewriteRule ^(.*)$ careers/$1 [L]  

## To internally redirect /dir/foo to /dir/foo.php 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+?)/?$ $1.php [L] 

## To internally redirect /dir/foo to /dir/foo.html 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule ^(.+?)/?$ $1.html [L] 
+0

感谢大师。你的代码有效,但它已经打破了你昨天帮助我的漂亮的网址代码。请参阅我的编辑请和帮助。谢谢:) –

+0

仍然没有快乐'http:// blog.example.co.uk/post/153/title-of-post'转到'Error 500' :( –

+0

随着每一个改变你带来新的URL。 “http:// blog.example.co.uk/php/test.php”URL发生了什么?如果得到500,然后检查Apache error.log并在此处报告错误文本 – anubhava