I would like to do the following:
redirect /about to /about.php (hide the extension)
redirect /(anything else) to /content.php?p=(anything else)
while keeping the root http://domain.com to /index.php (without showing /index.php)
I tried this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} !-f
RewriteRule "^about$" about.php [NC,L]
RewriteRule ^((/+[A-Za-z0-9\-]+/)*[A-Za-z0-9\-]+)?$ /_content.php?p=$1 [NC,L]
It succeeds to achieve the item 1 and 2, but this also rewrites the root http://domain.com to http://domain.com/_content.php?p=.
What have I done wrong? Thank you for your suggestions!
You can use these rules:
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ content.php?p=$0 [QSA,L]
Related
I have some directories:
/
/dash
/something
I want to make htaccess to redirect all traffic to it's subfolder index.php , which i did, when i type it works
example.com/dash or example.com/something
But my problem is when i try something like this example.com/dash/login or example.com/dash/another
in this case i'm redirected to / directory
Here is my htaccess in / directory
https:// we.tl/t-NtTDlYKBHr
Options -Indexes -MultiViews +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!dash/)(.+)$ /index.php?u=$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^dash/(.+)$ /dash/index.php?u=$1 [NC,QSA,L]
And in /dash
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
https:// we.tl/t-lhgQ03tTGE
I am not expert on this. but I think you achieve it by something like this.
put this file in your parent directory
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^none/ none/index.php [NC,L,QSA]
RewriteRule ^dash/ dash/index.php [NC,L,QSA]
RewriteRule ^something/ something/index.php [NC,L,QSA]
RewriteRule ^ index.php [NC,L,QSA]
also if you put htaccess in every directory you may use this in all directories.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [NC,L,QSA]
I'm basics to htaccess. I have an issue with htacess SEO Friendly URL.
For Ex:
If the URL is like www.example.com/A then htaccess should redirect to browse-category.php?alphabet=$1
My Code, but not working:
RewriteCond %{REQUEST_URI} [a-zA-Z]{1}$
RewriteRule ^([a-zA-Z0-9-/]+)$ browse-category.php?alphabet=$1
If URL is like this www.example.com/add-business then it should redirect to $1.php.
Please help me and thanks in advance
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
# if a matching .php file exists then internally forward /file to /file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /$1.php [L]
# otherwise forward to browse-category.php?alphabet=$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ browse-category.php?alphabet=$1 [L,QSA]
I am having a htaccess setting which already rewrite all request to index.php . but now i am having a condition where i want to rewrite (i am not sure how to do or which to choose) a subfolder /admin to index.php?route=admin/login , yes with the exact url
Expectation
www.domain.com/admin
rewrite to
www.domain.com/index.php?route=admin/login
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/install(.*)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
#########################################
##I expect the line below will go to the url , but when i enter the subfolder , the page remain at the index
RewriteRule ^admin/(.*)$ /$1?route=admin/login [R=301,L]
Try placing this in /admin/.htaccess:
RewriteEngine On
RewriteBase /admin/
RewriteRule ^$ /index.php?route=admin/login [R=301,QSA,L]
Rewrite to admin login from www.domain.com/admin
RewriteRule ^admin$ /index.php?route=admin/login [R=301,L]
Rewrite other requests, example:
www.domain.com/admin/list_users
www.domain.com/admin/send_mail
etc.
RewriteRule ^admin/(.*)$ /index.php?route=admin/$1 [R=301,L]
UPD.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/install(.*)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php [L]
#########################################
##I expect the line below will go to the url , but when i enter the subfolder , the page remain at the index
#RewriteRule ^admin/(.*)$ /$1?route=admin/login [R=301,L]
AND from php file instead $_GET['route'] use $_SERVER['REQUEST_URI']
OR UPD domain.com/admin/login
RewriteEngine On
RewriteRule ^admin/(.*)$ /index.php?route=admin/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !^/install(.*)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php [L]
#########################################
When i type anything beyond my url path Eg: http://example.com/doctorlist/ngffghf5235235 , I want it to get redirected to my home page i,e.. http://example.com . How can I do it .
I have my .htacess as follow
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !/(css|images|js)/
RewriteRule ^home/(.*)$ index.php [QSA]
RewriteRule ^doctorlist/(.*)$ innerpage.php [QSA]
RewriteRule ^appointment-list/(.*)$ detailspage.php?doc_id=$1 [QSA]
RewriteRule ^register-plus-appointment-form/(.*)$ register_plus_appointment_form.php?doc_id=$1&time_id=$2&date=$3&time=$4 [L,QSA]
RewriteRule ^appointment-form/(.*)$ appoint_form.php [L,QSA]
RewriteRule ^appointment-confirm-form/(.*)$ appointment_form.php [L,QSA]
to redirect every request to a certain page, eg index.php
RewriteRule (.*) /index.php [L]
hope this helps
According to your tags, I assume you need this for your Zend Framework application. So this will do the job :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
See : http://framework.zend.com/manual/1.12/en/zend.application.quick-start.html
I know there are many topics. I tried them many times, but it doesn't work.
What do I want?
Instead of example.com/en/file.php, users see only example.com/en/file.
My .htaccess file:
DirectoryIndex index.php index.html
RewriteEngine on
*RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ /$1.php*
ErrorDocument 404 /index.php
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^ru\/index\.php$ "http\:\/\/example\.com\/ru\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^en\/index\.php$ "http\:\/\/example\.com\/en\/" [R=301,L]
etc. for every language
What do I have to add to hide extensions?
After it works, should I use links between pages as "file.php" or only "file"?
Perhaps something like this.
Modify as you see fit for more specific pattern matching.
RewriteRule ^(?:(.*)/)?(.*)$ $2.php?lang=$1
Rewrites:
/en/fun => /fun.php?lang=en
/ru/fun => /fun.php?lang=ru
/fun => /fun.php?lang=
DirectoryIndex index.php index.html
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ $1.php [L,QSA]
In your links, don't use extensions.
Fixed by adding one line:
RewriteEngine on
**Options -Multiviews**
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ $1.php [L,QSA]