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]
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 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
This is my first htaccess file.
this is what i have written
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(css|js|png|jpg|gif|otf|eot|svg|ttf|woff|jpeg)$ - [L]
RewriteRule ^([^/]*)/([^/]*)$ maincategory/index.php?main=$1&sub=$2 [L,QSA,NC]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ subcategory/index.php?main=$1&sub=$2&cat=$3 [L,QSA,NC]
The problem what I am facing is both are pointing to maincategory.
How can I redirect based on number of "/" in the URL?
Thanks in advance.
Rearrange the rules and try it this way. Let me know if that works for you.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.(css|js|png|jpg|gif|otf|eot|svg|ttf|woff|jpeg)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ subcategory/index.php?main=$1&sub=$2&cat=$3 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)$ maincategory/index.php?main=$1&sub=$2 [L,QSA,NC]
guys. I'm trying to add a third rewrite condition in my .htaccess. The problem is, I have no idea how to add another one. So if anyone has a good in-depth tutorial on it I would be greatful.
Anyway back to business. Here is my current code:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ users.php?name=$1 [QSA,L]
The above as you might see removes the .php extensions and makes all files that don't exist go to users(IE: website.com/user goes to user's profile page).
So now I need to add one for the forum. I would like it rewrite like "website.com/Group/Category/Thread".
Is this even possible, or do I need to lower my expectations for this? Any help would be greatly appreciated. Thanks :D
Hmm I remember posting this answer :)
Anyway you can create a new rule on top of previous rules like this (and replace /Group/Category/Thread with whatever you have) :
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^forum/?$ /Group/Category/Thread [L,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ users.php?name=$1 [QSA,L]
You can insert more rules. Given that you want these rules to be matched before your final catch-all to user.php, you should place them before that final rule.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
# match forum, forum/group, forum/group/category and forum/group/category/thread urls
RewriteRule ^forum/?$ forum.php?group=$1&category=$2&thread=$3 [L]
RewriteRule ^forum/([^/]+)/?$ forum.php?group=$1 [L]
RewriteRule ^forum/([^/]+)/([^/]+)/?$ forum.php?group=$1&category=$2 [L]
RewriteRule ^forum/([^/]+)/([^/]+)/([^/]+)/?$ forum.php?group=$1&category=$2&thread=$3 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ users.php?name=$1 [QSA,L]