简体   繁体   中英

Creating SEO friendly URLs using apache mod_rewrite

I am trying to convert my ugly URL into SEO friendly URLs using apache mod_rewrite .

This is how my current URL s look like:

index.php?p=search
index.php?p=contact
index.php?p=my-account&user=1
index.php?p=my-account&user=1

This is what I expect from rewriting:

mydomain.com/search
mydomain.com/contact
mydomain.com/my-account/1
mydomain.com/my-account/1

If I passed one query string through my URL. I can do it in my .htaccess file something like this. But not sure how to do it when query string more than one in URL .

# Create SEO friendly URL 
# Eg: index.php?p=search to domain/search
<ifModule mod_rewrite.c>

# Turn on the engine:
RewriteEngine on

# Redirect certain paths to index.php:
RewriteRule ^(search|contact)/?$ index.php?p=$1 

</ifModule>

This is working if URL has one string. Can anybody tell me how I do this for more query strings.

Thank you.

You can do:

<ifModule mod_rewrite.c>

# Turn on the engine:
RewriteEngine on

# Redirect certain paths to index.php:
RewriteRule ^(search|contact)/?$ index.php?p=$1 [L,QSA,NC]

RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?p=$1&user=$2 [L,QSA,NC]

</ifModule>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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