I am using this htaccess code to create a rewrite rule
RewriteCond %{HTTP_HOST} ^my\.domain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
RewriteRule ^(.*)$ index.php?p=$1.php [L,QSA]
i want to rewrite pages like
http://my.domain.net/index.php?p=tickets/openticket to look like http://my.domain.net/tickets/openticket
but its just showing index.php without the ?p=...
Try this code as your first rules:
RewriteCond %{THE_REQUEST} /index\.php\?p=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+?)/?$ index.php?p=$1 [L,QSA]
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
try this.
Related
I'm trying to beautify URL's for SEO from http://example.net/dashboard.php?action=news to http://example.net/news
And it's working with this code
RewriteEngine On
RewriteCond %{THE_REQUEST} \/+dashboard\.php\?([^\&]+) [NC]
RewriteRule ^ %1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ dashboard.php?action=$1 [L,QSA]
But I want to edit more PHP files, for example, http://example.net/user.php?action=profile to http://example.net/profile
If I use this code again in the same .htaccess file
RewriteEngine On
RewriteCond %{THE_REQUEST} \/+user\.php\?([^\&]+) [NC]
RewriteRule ^ %1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ user.php?action=$1 [L,QSA]
It won't work, only dashboard.php one is working properly.
Can you please help me with this?
Thank you in advance.
Your current Rewriterules are to general.
[^/]+
matches everything which has no "/", else its matching everything.
So basicly your first rule
RewriteRule ^([^/]+)/?$ dashboard.php?action=$1 [L,QSA]
matches everytime. profile/ will always redirected to dashboard.php?acton=profile.
Your .htaccess should look like:
RewriteEngine On
RewriteCond %{THE_REQUEST} \/+dashboard\.php\?([^\&]+) [NC]
RewriteRule ^ %1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(news)/?$ dashboard.php?action=$1 [L,QSA]
RewriteCond %{THE_REQUEST} \/+user\.php\?([^\&]+) [NC]
RewriteRule ^ %1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(profile)/?$ user.php?action=$1 [L,QSA]
As you can see i switched
[^/]+
with more explicit regex.
I am trying to rewrite an ugly URL that's using two properties. For example, I want example.com/stories/?url=how-are-you?num=5 to be example.com/stories/how-are-you/5 I have rewritten the first property, but I don't know how to rewrite the num property. Here's my .htaccess file:
RewriteEngine On
RewriteBase /stories/
RewriteCond %{THE_REQUEST} /\?url=([^&\s]+) [NC]
RewriteRule ^ %1? [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ index.php?url=$1 [L,QSA]
Try :
RewriteEngine On
RewriteBase /stories/
RewriteCond %{THE_REQUEST} /\?url=([^&\s]+)&num=([0-9]+) [NC]
RewriteRule ^ %1/%2? [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?url=$1&num=$2 [L,QSA]
I have three four pages
page.php?s=defaultpage
page.php?p=defaultpage
blog.php?post=defaultpage
projects.php?view=defaultpage
I have this exisiting URL redirect code snippet. The fourth page is new, and I would like to write a condition for that to only show projects/defaultpage
How do I achieve this with the existing Rewrite condition.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Options -MultiViews
RewriteEngine On
RewriteBase /Renu/
RewriteCond %{THE_REQUEST} /page\.php\?([a-z])=([^&\s]+)
RewriteRule ^ %1/%2? [R=302,NE,L]
RewriteCond %{THE_REQUEST} /blog\.php\?post=([^&\s]+) [NC]
RewriteRule ^ blog/%1? [R=302,NE,L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteRule ^blog/([^/]+)/?$ blog.php?post=$1 [L,NC,QSA]
RewriteRule ^([a-z])/([^/.]+)/?$ page.php?$1=$2 [L,QSA]
Just add this line, before the last line:
RewriteRule ^projects/([^/]+)/?$ project.php?view=$1 [L,NC,QSA]
RewriteRule (.)/(.)/(.*)/$ /?view=$1&$2=$3
in php with get is :
example.com/?view=profile&nick=NickName
with .htaccess
example.com/profile/NickName/
My link is
search?c=category&s=product
I have already removed the .php with htaccess, everything is working apart from when a user searches, the first page will show the link above, I want to show the link as below:
search/category/product
I tried the below code:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^product/(.*)/(.*)/(.*) product.php?id=$1&c=$2&name=$3
RewriteRule ^search/(.*)/(.*)/(.*) search.php?c=$1&s=$2&page=$3
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{THE_REQUEST} \ /+search\?c=([^&\ ]+)&s=([^&]+)
RewriteRule ^ /search/%1/%2? [L,R]
What am I missing in the above?
Have rules this way:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /site/
RewriteCond %{THE_REQUEST} /search\?c=([^&\s]+)&s=([^&\s]+) [NC]
RewriteRule ^ search/%1/%2? [L,R]
RewriteRule ^product/([^/]+)/([^/]+)/([^/]+)/?$ product.php?id=$1&c=$2&name=$3 [L,QSA]
RewriteRule ^search/([^/]+)/([^/]+)/([^/]+)/?$ search.php?c=$1&s=$2&page=$3 [L,QSA]
RewriteRule ^search/([^/]+)/([^/]+)/?$ search.php?c=$1&s=$2 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
i am trying to force non-www to www and its working as aspected:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
now if i visit www.example.com/registration it works great.. but when i am accessing the same url from an link it works but adds index.php?/ in the url like this:
www.example.com/index.php?/registration
i am new to .htaccess programming.. i can understand i need ot modify the below lines.. but i dont know how to modify in such a way so that i does not add index.php?/ in the url...
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
any help or suggestion would be great help.. thanks in advance
Swap the order of your rules:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]