繁体   English   中英

.htaccess重写或子域

[英].htaccess rewrite or subdomain

这是我目前显示的网址;

http://blog.example.co.uk/post?id=152&title=titleofpost

这是我的htaccess,如下所示;

要将/dir/foo.php从外部重定向到/ dir / foo

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

在内部将/ dir / foo重定向到/dir/foo.php

RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]

博客子域

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

如何显示网址为;

http://blog.example.co.uk/post/titleofpost

像这样:

Options -MultiViews
RewriteEngine On

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

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

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

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM