简体   繁体   中英

How Can We Rewrite <a href> urls using .htaccess

I am having <a href> tags on website and user go to next page with parameters added to urls depending on parameters selected from < ahref> . The difference in my problem is on my website when user clicks on <a href> url it should be rewritten to seo friendly url

For watching it live you can see here -

url:- expertsusa.org/page1.php?id=4&name=Medical-Category is not rewritten to expertsusa.org/page1/Medical-Category and sometimes it is successfully rewritten but shown 404 Page and weird thing is both .htaccess file and page1.php file are in same root folder of website

Example -

<a href="page1.php?param=4&name=Medical-Category">Medical Category</a>`

You can see in this paramter i am passing values through parameters. I want to rewrite this to simple seo form like below -

Url - www.example.com/page1/Medical-Category

Following is the mod_rewrite Module Code in my .htaccess file

ErrorDocument 404 default 
<IfModule mod_rewrite.c>

Options -MultiViews
RewriteEngine On

#RewriteRule ^ /%1/%2? [R=302,L,NE]
#RewriteRule ^(page1)/([\w-]+)/?$ $1.php?id=4&name=$2 [L,NC,QSA]


RewriteRule  ^/ViewCategories/([0-9]+)/(.*)/(.*)/(.*)$  ViewCategories.php?param=$1
RewriteRule    ^/Add-Expert-Listing/$1   Add-Expert-Listing.php    [NC,L]   
RewriteRule    ^/SearchResult/$1   SearchResult.php    [NC,L]    
RewriteRule    ^/Pricing/$1   Pricing.php    [NC,L]   
RewriteRule    ^/My-Lists/$1   MyLists.php    [NC,L]   
RewriteRule    ^/My-Package/$1   MyPackage.php    [NC,L]   
RewriteRule    ^/Change-Password/$1   Change-Password.php    [NC,L]   
RewriteRule    ^/faq/$1   faq.php    [NC,L]   
RewriteRule    ^/ContactUs/$1   ContactUs.php    [NC,L]   
RewriteRule    ^/ViewCategories/$1   ViewCategories.php    [NC,L]   
RewriteRule    ^/Profile/$1   Profile.php    [NC,L]   
</IfModule>

You can use these rules in your site root .htaccess:

Options -MultiViews
RewriteEngine On

RewriteCond %{THE_REQUEST} /(page1)\.php\?id=4&name=([^\s&]+)  [NC]
RewriteRule ^ /%1/%2? [R=302,L,NE]

RewriteRule ^(page1)/([\w-]+)/?$ $1.php?id=4&name=$2 [L,NC,QSA]

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