问题描述
我想通过的.htaccess
,以创建一个自定义HTTP链接头捕捉当前的 rewrited网址
脚本网址:
HTTP://localhost/index.php
在rewrited网址:
的http://本地主机/新闻
htaccess的:
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
?重写规则^(新闻)$的index.php和放大器; M = $ 1 [NC,L,QSA]
重写规则^(。*) - [E = ORIGPROTO:HTTP]
(。*)重写规则^ - [E = ORIGURI:%{HTTP_HOST}]
重写规则^(。*) - [E = ORIGQRY:%{REQUEST_URI}]
输出:
ORIGPROTO = HTTP
ORIGURI =本地主机
ORIGQRY =的index.php
我期待ORIGQRY等于新闻
我的问题是如何通过htaccess的捕捉当前rewrited网址是什么?
修改1
重写规则^(*) - [E = ORIGPROTO:HTTP]
(。*)重写规则^ - [E = ORIGURI:%{HTTP_HOST}]
的RewriteCond%{} REQUEST_FILENAME -d
的RewriteCond%{REQUEST_URI} ^(。*)[^ /] $
重写规则。 %1 / [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*?)(/ {2})(。*)$
重写规则。 %1 /%3 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)_(。*)$
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\º(。*)$
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\!(。*)$
重写规则。 %1 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\(。*)$
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\'(。*)$
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\(。*)$
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\(。*)$
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\(。*)$
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\((。*)$
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\)(。*)$
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\ [(。*)$
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\(。*)$
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\ {(。*)$
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\}(。*)$
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^ \(。*):$(*)。
重写规则。 %1%2 [R = 301,L]
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(。*)\ +(。*)$
重写规则。 %1%2 [R = 301,L]
#avoid大写和放大器;重音
的RewriteCond%{REQUEST_METHOD}!= POST
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{REQUEST_URI} ^(A | A | A |Æ|æ| A | A | A | A | A | A | A | A)(*?)(。*?)$
重写规则。 %1A%3 [R = 301,L]
。
。
。
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(新闻)/ $的index.php和放大器; M = $ 1 [NC,QSA,E = ORIGQRY:$ 1,L]?
#404页
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^ $的index.php PT = 404安培(*);?ACC = 404_page [L]
头始终设置链接< HTTP://cache_api.com/% {ORIGPROTO} E://%{ORIGURI} E&{ORIGQRY} e所取代;相对= timegate
规则在他们的presence在.htacces的顺序执行。在这里,你的第一个规则修改 REQUEST_URI
到的index.php
。
FIX:更改您的规则的顺序:
重写规则^(*) - [E = ORIGPROTO:HTTP]
(。*)重写规则^ - [E = ORIGURI:%{HTTP_HOST}]
的RewriteCond%{THE_REQUEST} \ S / +([^ \ s?] +)
重写规则^ - [E = ORIGQRY:%1]
头始终设置链接< HTTP://cache_api.com/% {ORIGPROTO} E://%{ORIGURI} E /%{ORIGQRY} e所取代;相对= timegate
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^(新闻)/ $的index.php?M = $ 1 [NC,QSA,L]
I want to capture the current rewrited url via .htaccess
in order to create to a custom HTTP Link header.
the script url :
http://localhost/index.php
the rewrited url :
http://localhost/news
the htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(news)$ index.php?&m=$1 [NC,L,QSA]
RewriteRule ^(.*) - [E=ORIGPROTO:http]
RewriteRule ^(.*) - [E=ORIGURI:%{HTTP_HOST}]
RewriteRule ^(.*) - [E=ORIGQRY:%{REQUEST_URI}]
the output:
ORIGPROTO = http
ORIGURI = localhost
ORIGQRY = index.php
I am expecting ORIGQRY to be equal to 'news'
My question is how to capture the current rewrited url via htaccess?
EDIT 1
RewriteRule ^(.*) - [E=ORIGPROTO:http]
RewriteRule ^(.*) - [E=ORIGURI:%{HTTP_HOST}]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} ^(.*)[^/]$
RewriteRule . %1/ [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*?)(/{2,})(.*)$
RewriteRule . %1/%3 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)_(.*)$
RewriteRule . %1-%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\º(.*)$
RewriteRule . %1%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\!(.*)$
RewriteRule . %1 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\,(.*)$
RewriteRule . %1%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\'(.*)$
RewriteRule . %1%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\"(.*)$
RewriteRule . %1%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\"(.*)$
RewriteRule . %1%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\"(.*)$
RewriteRule . %1%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\((.*)$
RewriteRule . %1%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\)(.*)$
RewriteRule . %1%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\[(.*)$
RewriteRule . %1%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\](.*)$
RewriteRule . %1%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\{(.*)$
RewriteRule . %1%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\}(.*)$
RewriteRule . %1%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\:(.*)$
RewriteRule . %1-%2 [R=301,L]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*)\+(.*)$
RewriteRule . %1-%2 [R=301,L]
#avoid uppercase & accented
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.*?)(A|Â|â|Æ|æ|À|à|Å|å|Ã|ã|Ä|ä)(.*?)$
RewriteRule . %1a%3 [R=301,L]
.
.
.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(news)/?$ index.php?&m=$1 [NC,QSA,E=ORIGQRY:$1,L]
#404 page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?pt=404&acc=404_page [L]
Header always set Link "<http://cache_api.com/%{ORIGPROTO}e://%{ORIGURI}e%{ORIGQRY}e>;rel=timegate"
Rules are executed in the order of their presence in .htacces. Here your first rule is modifying REQUEST_URI
to /index.php
.
FIX: Change the order of your rules:
RewriteRule ^(.*) - [E=ORIGPROTO:http]
RewriteRule ^(.*) - [E=ORIGURI:%{HTTP_HOST}]
RewriteCond %{THE_REQUEST} \s/+([^\s?]+)
RewriteRule ^ - [E=ORIGQRY:%1]
Header always set Link "<http://cache_api.com/%{ORIGPROTO}e://%{ORIGURI}e/%{ORIGQRY}e>;rel=timegate"
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(news)/?$ index.php?m=$1 [NC,QSA,L]
这篇关于htaccess的 - 如何捕捉当前rewrited网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!