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]
Related
I got a question, I'm trying to edit my url using htaccess and its somehow broken...
My url: url.com/room.php?videoID=Blabla
The url I want: url.com/room/Blabla
I wrote something which actually worked, but considered file.php as a videoID and returned error.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^es/([a-zA-Z0-9-]+)$ room.php?roomID=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-]+)$ room.php?roomID=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Use this in your .htaccess:
RewriteEngine On
RewriteRule ^room/([^/]*)$ /room.php?videoID=$1 [L]
It will give you the following URL: url.com/room/Blabla
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 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 am using this code for url rewriting
What its not doing is if there is directory i want to go like this its going to profile.php any idea how to do hide extension php in subdirectory
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) profile.php?username=$1
try this
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]