I want to make this URL clean:
news.php?post=13
but when I tried to use this RewriteRule:
RewriteRule ^(news)\/([0-9]+)\/?$ news.php?post=$2
It only shows the news page, no post content.
It has been bugging me for the past 2 days, and I can`t figure it out. Can someone help me with this?
Here's the entire Htaccess
RewriteEngine on
RewriteRule ^(news)\/([0-9]+)\/?$ news.php?post=$1
RewriteRule ^(verify)/(.*)/([a-zA-Z0-9_-]+)$ validate_account.php?usr=$2&hash=$3 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^(news)\/([0-9]+)\/?$ news.php?post=$2
use $1
Try this config:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^news/([0-9]+)\/?$ news.php?post=$1
RewriteRule ^verify/(.*)/([a-zA-Z0-9_-]+)$ validate_account.php?usr=$1&hash=$2 [QSA,L]
RewriteRule ^(.*)$ $1.php
Try this method:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^news/([0-9]+)\/?$ news.php?post=$1
Related
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've been searching on the web but nothing seems to work. I'm working in local with Apache and Xampp. I have created an .htaccess file and rewrote all urls ending with .php and .html to remove the extension and I have created a custom 404 page. Everything worked fine. However, now I'm trying to rewrite a dynamic url that looks like
/TotinCoblan/update/Wine?id=2
to
/TotinCoblan/update/Wine/2
and I keep getting error 500. this is my .htaccess file. From what I understood,
RewriteCond %{REQUEST_FILENAME} !-f
should avoid infinite loops.
Any help would be much appreciated.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/update/Wine/([0-9]+)/?$ /update/Wine?id=$1 [L]
ErrorDocument 404 TotinCoblan/errors/404
Try this code:
ErrorDocument 404 /TotinCoblan/errors/404
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^update/Wine/([0-9]+)/?$ /update/Wine?id=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
I finally used this code, I had to use RewriteCond %{REQUEST_FILENAME} !-f since the page was loading only after reloading two time. With that instructions loads the first time.
RewriteCond %{REQUEST_FILENAME} !-f
ErrorDocument 404 /TotinCoblan/errors/404
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ - [L]
RewriteRule ^update/Wine/([0-9]+)/?$ update/Wine.php?id=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
You should change your -f checks to use %{DOCUMENT_ROOT}${REQUEST_URI} instead. The problem with %{REQUEST_FILENAME} is that mod_rewrite will partially attempt to map the URI to a file, and it accounts for PATH INFO, which means if the request is something like:
/something/foo/anything/
and you happen to have an existing file/script at:
/something/foo.php
then the RewriteCond %{REQUEST_FILENAME}\.php -f check will be true, and the URI that it assumes you meant is:
/something/foo.php/anything/
And, like your code is doing, the .php is appended to the end instead:
/something/foo/anything/.php
and that causes the infinite loop. Try something like:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/update/Wine/([0-9]+)/?$ /update/Wine?id=$1 [L]
ErrorDocument 404 TotinCoblan/errors/404
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]
I am trying to use .htaccess to make my url's "prettier".
Changing domain.com/page/val1
To domain.com/page.php?var1=val1
If possible, I would like it to work with 2 variables as well:
Changing domain.com/page/val1/val2
To domain.com/page.php?var1=val1&var2=val2
This is my current .htaccess file that works to remove the .php extension:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
I've found other topics with solutions similar to adding something like this:
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /$1/$2?var1=$3&var2=$4 [L,QSA,NC]
I've tried many ways to modify it and it never seems to work.
Any help would be appreciated. Thanks.
Try this code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?var1=$2 [L,QSA]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ $1.php?var1=$2&var2=$3 [L,QSA]