问题
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