Reputation: 37
I am new on .htaccess My current url is :
http://localhost/www.zeeshan.com/details.php?p_id=999
and if i want to display my url like this its work good for me.
http://localhost/www.zeeshan.com/details/999
my .htaccess code is
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /www.zeeshan.com/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^details/([^/]+)$ details.php?p_id=$1 [NC,L]
My problem is that when use this link i can not obtain my correct answer:
http://localhost/www.zeeshan.com/details.php?p_id=999&p_title=nokia%20mobile%20for%20sale
i used this .htaccees code
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /www.zeeshan.com/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^details/(\d+)-([\w-]+)$ details.php?p_id=$1&p_title=$2 [NC,L]
after using this link i want like this:
http://localhost/www.zeeshan.com/details/999/nokia-mobile-for-sale
i read many time this topic in the given link to solve my problem but failed to get my correct out put. every time and got page not found error. Rewriting URL with .htaccess local in XAMPP
please help me to solve my problem.
Upvotes: 1
Views: 98
Reputation: 784958
Your regex is incorrect actually. Use this rule:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /www.zeeshan.com/
## convert spaces to hyphens
# executes **repeatedly** as long as there are more than 1 spaces in URI
RewriteRule "^(\S*) +(\S* .*)$" $1-$2 [L,NE]
# executes when there is exactly 1 space in URI
RewriteRule "^(\S*) (\S*)$" $1-$2 [L,R=302,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^details/(\d+)/([^/]+)/?$ details.php?p_id=$1&p_title=$2 [NC,L,QSA]
Upvotes: 1