I have an htaccess file where my urls are overwritten.
This works great.
Now I want the ending ".html" to be inserted automatically at all urls.
If there is "/" at the end, this should be removed.
Here is the content of my .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
Related
I had added this code in .htaccess for removing .php extension from the url's.Also I had written a code for making blog url seofriendly like https://url.com/posttitle
<IfModule mod_rewrite.c>
#removing extension from url
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
#blog
#if the file with the specified name in the browser doesn’t exist, or the directory in the browser doesn’t exist then procede to the rewrite rule below
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteRule ^(.*)$ blog_detail.php?id=$1 [QSA,L]
</IfModule>
I had added links like Home.
Home
How to remove index from url in this case?
You can simply use a "/" in your href attribute when navigating to your root (index.html/.php)
i have an index.php in the following folder:
https://example.com/folder1/folder2/index.php
If the URL is
https://example.com/folder1/folder2/93j3h233j3
then redirect to the index.php but the URL should stay the same!
My idea: i call a php file without .php first and then try to redirect...
RewriteRule ^folder1/folder2/([^\.]+)$ /folder1/folder2/index.php?&%{QUERY_STRING}
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^folder1/folder2/(.*)$ /folder1/folder2/index.php? [R=302]
This doesnt work.
And keep the name! but how?
Any Idea?
Thank you
You can have your rule as this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(folder1/folder2)/.+$ $1/index.php [L,NC]
There is no need to use your first rule.
I have PHP file page.php, and with this file I dynamically change content. So how can I make with htaccess to change link from www.example.com/page.php?page=somepage to www.example.com/somepage?
Add the following code to your htaccess file :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /page.php?pape=$1 [NC,L]
This will rewrite your url
example.come/somepage
to
example.come/page.php?page=somepage
I want to use .htaccess files so that if someone visits an old URL on our new website such as website.com/oldpage.asp .htaccess first checks to see if website.com/oldsite/oldpage.asp is on our server. And if no file is there redirect them to old.website.com/oldpage.asp where a copy of our old website exists.
For some reason only the .htaccess file in the /oldsite/ folder is executing.
Here is my .htaccess file for my site root which checks if the file exists on the new site and if not redirects to /oldsite/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /oldsite/$1 [NC,QSA,L]
Then in /oldsite/ its supposed to check if the file again exists, and if not redirect again.
RewriteEngine On
RewriteOptions inherit
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://old.website.com/$1 [R=301,NC,QSA,L]
You don't need 2 .htaccess for this.
Have this rule in site root .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/oldsite/$1 -f
RewriteRule ^(.*)$ oldsite/$1 [NC,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://old.website.com/$1 [R=301,L]
Then remove /oldsite/.htaccess and test this after clearing your browser cache.
I want to redirect only php files and files with no file extension like these:
http://www.test.com/test.php
http://www.test.com/TEST
I have this htaccess script, which redirects php files to target.php:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^\.]+\.php$ /target.php [L,NC]
Now I need to add files with no extension to this redirect.
Thanks for help!
These rules should do the job.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^[^\.]+\.php$ /target.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[^\.]*[^/\.]$ /target.php [L,NC]
The redirect will work for http://www.test.com/TEST as long as you do not have folder or file named TEST in your site.