I use this rules
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)/?$ /used-details.php?id=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
to rerwrite all the www.domain.com/1234 to www.domain.com/used-details.php?id=1234
and it works correctly.
How can have the www.domain.com/used-details/1234 instead of the www.domain.com/1234
Thank you
Use this
RewriteEngine on
RewriteRule used-details/(.*)/ used-details.php?id=$1
Try this:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^used-details/([0-9]+)/?$ /used-details.php?id=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
It will change www.domain.com/used-details/1234 to www.domain.com/used-details.php?id=1234
Related
in my website two rewrite rule are conflicting with each other
i have url for my users like= http://twekr.com/sam
and all my website pages open like http://twekr.com/login
now here is htaccess file rules
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?user=$1
Now only this rule works because its loaded first =
RewriteCond %{REQUEST_FILENAME} !-d
And if i put profile rewrite rule above
RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?user=$1 (then this works)
and this doesnt
RewriteCond %{REQUEST_FILENAME} !-d (does not work)
What is the problem in htaccess rule?
You should check for presence of .php file before adding .php extension:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/?$ profile.php?user=$1 [L,QSA]
I have this code for removing the .php extension from a URL like this: domain.com/file.php to this: domain.com/file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Is there any way to remove the .php extension from domain.com/file.php?action=123456 to domain.com/file?action=123456 ?
Any help would be appreciated!
Try:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule (.*) $1.php [L,QSA]
Try this rule :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteCond %{THE_REQUEST} /file\.php\?action=([^&\s]+) [NC]
RewriteRule ^ file?action=%1 [NC,L,R]
Okay, for those who are wondering, I basically answered my own question. My original code works for all. :)
Answer:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
So I have an article.php and what I'm trying to do is instead of article.php?id=1. I'm trying to do article/1. So here's what I'm doing
RewriteRule ^/article/([0-9]+)\.php /article.php?id=$1
All I get with this is
The requested URL /article/.php was not found on this server.
I think this has to do with the rest of my rewriting. Here's all the code I got
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^/article/([0-9]+)\.php /article.php?id=$1
Any ideas?
Have you tried something like:
RewriteRule ^article/([0-9]+)$ article.php?id=$1
Instead of what you have?
EDIT:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/([0-9]+)$ article.php?id=$1
RewriteRule ^([^\.]+)$ $1.php [NC,L]
So I have shortened article.php?id=10 to article/10. And it all seemed to work fine. But little did I know that it ruined the rest of my URLs. So with http://localhost/forgot/, I'd have to go to http://localhost/forgot/index to actually reach it. Here's what I'm using
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/([0-9]+)$ article.php?id=$1
RewriteRule ^([^\.]+)$ $1.php [NC,L]
I want to go to http://localhost/forgot/ instead of http://localhost/forgot/index/ Any ideas?
Have your rules like this:
Options -MultiViews
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/([0-9]+)$ article.php?id=$1 [L,QSA,NC]
# rewrite from /dir/file/ to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
I know this topic already been here, but I need help because I cant find an answer.
Here is my problem:
I am trying to change urls
example.com.au/admin/pages.php
to
example.com.au/admin/pages (without .php extention)
then I am trying to:
example.com.au/admin/edit.php?id=1
to
example.com.au/admin/edit/1
I have this .htaccess, please helkp me sort this problem. thanks
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.php
RewriteRule ^edit/([^/.]+)/?$ edit.php?id=$1
Try this :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^edit/(.*)/?$ edit.php?id=$1
RewriteRule ^(.*)$ $1.php
Try this
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
THIS IS WORKING, thanks everyone got my answer my self.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^admin/pages/edit/(.+)$ admin/pages/edit.php?id=$1 [L]