PHP $_GET and .htaccess rewrite

こ雲淡風輕ζ 提交于 2019-12-02 04:54:31

In your .htaccess you can have a couple of simple rules:

RewriteRule ^.*/listings/([a-zA-Z0-9_]+)/([a-zA-z0-9_]+)$ /listing/?property_type=$1&query=$2 [QSA,L]
RewriteRule ^.*/listings/forlease/$ /listing/?forlease=1 [QSA,L]

If your webserver is Apache, then you can use mod_rewrite.

Check out : http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html =)

RewriteRule ^.*/listing/([^/]*)/?$ listing/?$1=1 [NC,L]
RewriteRule ^.*/listing/([^/]*)/?(.*)$ listing/?property_type=$1&query=$2 [NC,L]

Try this, first checks for a single condition (http://...listing/forlease), otherwise rewrites to (http://...listing/field/query)

You might want:

RewriteRule ^.*/listing/([^/]*)/?$ listing/?$1=1&%{QUERY_STRING} [NC,L]
RewriteRule ^.*/listing/([^/]*)/?(.*)$ listing/?property_type=$1&query=$2&%{QUERY_STRING} [NC,L]

To keep any additional parameters in the query string.

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