简体   繁体   English

重写URL APACHE 2.4.9 htaccess

[英]Rewrite URL APACHE 2.4.9 htaccess

i am using apache 2.4.9 我正在使用Apache 2.4.9

i want to rewrite a url in htaccess 我想在htaccess中重写网址

https://localhost/balance.php/editbalance

when i enter above url it should be displayed like below 当我在网址上方输入时,应显示如下

https://localhost/editerapi/editbalance

i have tried this but its not working 我已经尝试过了,但是没有用

RewriteEngine On    # Turn on the rewriting engine
RewriteRule    ^editerapi/?$    balance.php   [NC,L]
RewriteCond %{REQUEST_URI} ^/editerapi [NC]
RewriteRule ^.*/([^/]+)/? balance.php/$1 [L] #POST 

MY REWRITE ENGINE IS ON 我的重写引擎已开启

the below code of hiding php extension is working 下面的隐藏php扩展名的代码正在工作

RewriteEngine On    # Turn on the rewriting engine
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [QSA,L]

In order to show the new URL in the browser's bar, you must redirect instead of rewrite, eg use the R|redirect flag 为了在浏览器栏中显示新的URL,您必须重定向而不是重写,例如,使用R|redirect标志

RewriteRule ^balance\.php/(.*)$ /editerapi/$1 [R,L]

Now the client requests the new URL /editerapi/... , and you must rewrite to 现在,客户端请求新的URL /editerapi/... ,并且您必须重写为

RewriteRule ^editerapi/(.*)$ /balance.php/$1 [L]

To prevent a rewrite loop, a RewriteCond is added. 为防止重写循环,添加了RewriteCond Now the redirect only happens, when balance.php is requested 现在仅当请求balance.php时才发生重定向

RewriteCond %{THE_REQUEST} " /balance\.php/"

Everything put together gives 一切放在一起

RewriteRule ^editerapi/(.*)$ /balance.php/$1 [L]

RewriteCond %{THE_REQUEST} " /balance\.php/"
RewriteRule ^balance\.php/(.*)$ /editerapi/$1 [R,L]

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

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