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
Related
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]
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.
Hi can any one help me write this htaccess code for the url mentioned below.
my url is soemthing like this http://localhost/worldofcontrol/search/ic3500a192c
and i want this to be changed to http://localhost/worldofcontrol/ic3500a192c
and my htaccess code is
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-Za-z0-9-]+)/?$ search/product_details.php?id=$1 [NC,L]
Following .htaccess doesn't work for root level page.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^demo\-blog/(.*)$ demo\-blog/index.php/$1 [L]
If I access http://example.com/demo-blog/blog/publish.html then it works by executing file on http://example.com/demo-blog/index.php/blog/publish.html but when I access http://example.com/demo-blog/ it doesn't load the page from http://example.com/demo-blog/index.php. The .htaccess file is on the domain root. http://example.com/
Please let me know why it doesn't rewrite the url for the home page.
Change your rule to this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^demo-blog(/.*|)$ demo-blog/index.php/$1 [L,NC]
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.