简体   繁体   中英

How to pass a value to any url using htaccess

I want to pass a string ( p=number ) to all the URL in my website

Example:

www.abc.com/p/1/my-filename-1

www.abc.com/p/2/my-new-filename-anything

This is my current code but it is not working:

<IfModule mod_rewrite.c>    
    Options +FollowSymLinks -Multiviews
    RewriteEngine On

    # Remove .php file extention
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^\.]+)$ $1.php [NC,L]


    # For individual page url
    #RewriteRule ^p/(.*)\.php $1.php?p=$2

</IfModule>

Try this rule, here we are getting digit from url and assigning it to the respective file with removed extension.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)/$ $1.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^p/([\d]+)/([\w-]+)$ $2.php?id=$1 [NC,L]

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