简体   繁体   中英

How can I redirect url in PHP using htaccess

I need some rewrite rules for URLs

I want:

www.dawsonautodetailing.com/?page=About-Us

Changed to:

www.dawsonautodetailing.com/page/About-Us or www.dawsonautodetailing.com/About-Us

I've already created .htaccess into my root folder.

Thank you for the help!

I've tried to google it but since i am new to .htaccess i don't even know where to begin:)

You can use the mod_rewrite module in Apache to redirect URLs in PHP using .htaccess.

To redirect a specific URL, you can use the following syntax in your .htaccess file:

RewriteEngine On  

RewriteRule ^old-url$ http://www.example.com/new-url [R=301,L]

This will redirect any requests for the URL "old-url" to "http://www.example.com/new-url" with a "301" redirect (permanent redirect).

You can also use regular expressions to match patterns in the URL and redirect accordingly. For example, if you want to redirect all requests for URLs starting with "old-directory" to "new-directory", you can use the following:

RewriteEngine On

RewriteRule ^old-directory/(.*)$ http://www.example.com/new-directory/$1 [R=301,L]

This will take any URL starting with "old-directory" and redirect it to the same URL, but starting with "new-directory" instead.

Be careful while modifying.htaccess as it can cause website to malfunction. It is always a good practice to take backup before making any changes.

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