Apache .htaccess URL Rewriting

夙愿已清 提交于 2019-12-14 02:28:38

问题


I would like to change a URL from this:

http://opportunityfinance.net/industry/industry_locator_proc.asp?organization={ORGANIZATION NAME}

To something like this:

http://opportunityfinance.net/industry/{ORGANIZATION NAME}

while still accessing the first url. Where {ORGANIZATION NAME} can equal a bunch of different names, really anything.

There must be an easy way to do this with a .htaccess file right?

Or maybe it would be better if we changed it to this:

http://opportunityfinance.net/organization={ORGANIZATION NAME}

whichever is easier I guess works for me. Thanks, you guys here are awesome!


回答1:


You must first capture the query string part with a RewriteCond and redirect the client to the new URL

RewriteEngine on
RewriteCond %{ENV:REDIRECT_SEO} !1
RewriteCond %{QUERY_STRING} organization=(.+)
RewriteRule ^/?industry/industry_locator_proc.asp /industry/%1? [R,L]

Now the client requests the new URL and you serve the request from the existing ASP

RewriteCond %{REQUEST_URI} !industry_locator_proc.asp
RewriteRule ^/?industry/(.*) /industry/industry_locator_proc.asp?organization=$1 [E=SEO:1,L]

The environment setting E=SEO:1 prevents an endless loop.

When everything works as it should, you can replace R with R=301.



来源:https://stackoverflow.com/questions/15243892/apache-htaccess-url-rewriting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!