URL扩展名隐藏:改写VS重定向 [英] URL extension hiding : rewrite vs redirect
问题描述
我看了很多的问题和答案,但我不能决定哪一个是好或如何使用的扩展隐藏这些方式的组合。
我想要什么是有一个URL重写例如计算器!那么还有哪些我应该做的有以下规则:
网址:中example.com/file.anyEXT ...显示的内容=> 404
网址:中=&GT example.com/unknown-Cat ...显示的内容; 404
网址:中=&GT example.com/cat1节目内容; example.com/cat1/index.php
网址:中=&GT example.com/cat1/index.php节目内容; 404
网址:中=&GT example.com/cat1/any...any节目内容; 404
网址:中example.com/cat1/11/title节目内容=> example.com/cat1/single.php(职位编号11)
但我的htaccess的文件只是做这样的:
网址:example.com/file.anyEXT
显示的内容=> example.com/index.php(应显示404)
网址:example.com/unknown-Cat
显示的内容=> example.com/index.php(应显示404)
网址:example.com/unknown-Cat/
显示破碎含量=>的index.php =>着负载的CSS和JS => (应显示404)
网址:example.com/file.anyEXT/
显示破碎含量=>的index.php =>着负载的CSS和JS => (应显示404)
网址:example.com/cat1
显示的内容=> example.com/cat1/index.php(正常工作!)
网址:example.com/cat1/index.php
显示的内容=> example.com/cat1/index.php(应显示404)
网址:example.com/cat1/any...any
显示的内容=> 404(正常工作!)
网址:example.com/cat1/11/title
显示的内容=> example.com/cat1/single.php(职位编号11)(正常工作!)
我有什么
mydomain- |
|
|
| __cat1- | __ htaccess的// CAT1的htaccess
| | __index.php
| | __single.php
|
| __cat2- | __ htaccess的// CAT2的htaccess
| | __index.php
| | __single.php
...
| __ htaccess的//根htaccess的
| __index.php //家庭页
我的htaccess根据大多数建议的方式:
< IfModule mod_rewrite.c>
#开启重写引擎
RewriteEngine叙述上
的RewriteBase /
<文件的.htaccess>
为了允许,拒绝
所有否认
< /文件>
选项所有-Indexes
#从WWW重定向。
RewriteEngine叙述上
的RewriteCond%{HTTP_HOST} ^ WWW \ .EXAMPLE \ .COM $ [NC]
重写规则^(。*)$ http://example.com/$1 [L,R = 301]
#删除的index.php从防爆pressionEngine网址
的RewriteCond%{THE_REQUEST} ^ GET。*指数\ .PHP [NC]
重写规则(。*?)指数\ .PHP /*(.*)/ $ 1 $ 2 [R = 301,NE,L]
#指示通过该网站的索引文件中的所有EE Web请求
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(。*)$ /index.php/$1 [L]
< / IfModule>
这是我用我的根文件夹,在我所有的子文件夹中,我有两个文件的index.php
和的single.php
和我的.htaccess这样在每一个子文件夹:
选项+了FollowSymLinks
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase / CAT1 /
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(\ d +)/ / $的single.php ID = $ 1安培(+?);?标题= $ 2 [L,QSA]
< / IfModule>
您可以使用:
的DocumentRoot /的.htaccess
:
< IfModule mod_rewrite.c>
<文件的.htaccess>
为了允许,拒绝
所有否认
< /文件>
选项所有-Indexes
RewriteEngine叙述上
的RewriteBase /
#从WWW重定向。
的RewriteCond%{HTTP_HOST} ^ WWW \ .EXAMPLE \ .COM $ [NC]
重写规则^(。*)$ http://example.com/$1 [L,NE,R = 301]
#404的index.php的网址
的RewriteCond%{} THE_REQUEST /index\.php[\s?/] [NC]
重写规则^ - [L,R = 404]
< / IfModule>
/cat1/.htaccess
:
选项+了FollowSymLinks
< IfModule mod_rewrite.c>
RewriteEngine叙述上
的RewriteBase / CAT1 /
的RewriteCond%{} THE_REQUEST /index\.php[?\s] [NC]
重写规则^指数\ .PHP $ - [L,R = 404]
?重写规则^(\ d +)/([^ /] +)/ $的single.php 1 ID = $&放大器;标题= $ 2 [L,QSA]
< / IfModule>
I have read lots of question and answers but i cant decide which one is better or how to use a combination of these ways of extension hiding.
what i want is to have a url rewriting like stackoverflow! so what else should i do to have these rules:
url: example.com/file.anyEXT... show content of => 404
url: example.com/unknown-Cat... show content of => 404
url: example.com/cat1 show content of => example.com/cat1/index.php
url: example.com/cat1/index.php show content of => 404
url: example.com/cat1/any...any show content of => 404
url: example.com/cat1/11/title show content of => example.com/cat1/single.php (post id 11)
but my htaccess files just do like these:
url: example.com/file.anyEXT
show content of => example.com/index.php (should show 404)
url: example.com/unknown-Cat
show content of => example.com/index.php (should show 404)
url: example.com/unknown-Cat/
show broken content of => index.php => cant load css and js => (should show 404)
url: example.com/file.anyEXT/
show broken content of => index.php => cant load css and js => (should show 404)
url: example.com/cat1
show content of => example.com/cat1/index.php (works fine!)
url: example.com/cat1/index.php
show content of => example.com/cat1/index.php (should show 404)
url: example.com/cat1/any...any
show content of => 404 (works fine!)
url: example.com/cat1/11/title
show content of => example.com/cat1/single.php (post id 11) (works fine!)
What i have
mydomain-|
|
|
|__cat1-|__.htaccess // cat1 htaccess
| |__index.php
| |__single.php
|
|__cat2-|__.htaccess // cat2 htaccess
| |__index.php
| |__single.php
...
|__.htaccess // root htaccess
|__index.php // home-page
my htaccess based on most suggested way:
<IfModule mod_rewrite.c>
# Enable Rewrite Engine
RewriteEngine On
RewriteBase /
<files ".htaccess">
order allow,deny
deny from all
</files>
Options All -Indexes
# Redirect from www.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
It is what i used in my root folder and in all my sub-folders i have two files index.php
and single.php
and i have .htaccess like this in every sub folders:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cat1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(\d+)/(.+?)/?$ single.php?id=$1&title=$2 [L,QSA]
</IfModule>
You can use:
DocumentRoot/.htaccess
:
<IfModule mod_rewrite.c>
<files ".htaccess">
order allow,deny
deny from all
</files>
Options All -Indexes
RewriteEngine On
RewriteBase /
# Redirect from www.
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,NE,R=301]
# 404 for index.php in URL
RewriteCond %{THE_REQUEST} /index\.php[\s?/] [NC]
RewriteRule ^ - [L,R=404]
</IfModule>
/cat1/.htaccess
:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cat1/
RewriteCond %{THE_REQUEST} /index\.php[?\s] [NC]
RewriteRule ^index\.php$ - [L,R=404]
RewriteRule ^(\d+)/([^/]+)/?$ single.php?id=$1&title=$2 [L,QSA]
</IfModule>
这篇关于URL扩展名隐藏:改写VS重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!