Due to request, every page needs to be prefixed with "index.php"; if the path was first /it, now it needs to be /index.php/it.
I have tried changing base url in settings.php. But it doesnot works.Tried rewriting in .htaccess also. I have tried the following code
RewriteBase /
RewriteCond %{HTTP_HOST} ^http://www.example.com/index.php [NC]
RewriteRule ^(.*)$ http://www.example.com/index.php [L,R=301]
But it doesnot works. Somebody help me please. Thanks in advance..
Make sure you have mod_rewrite enabled and try with this
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ http://www.example.com/index.php/$1 [L,R=301]
Remember that the $1 refers to the (.*) you have captured in the URL
You are not using your capture group (.*). You can refer to it using $1
RewriteRule ^(.*)$ http://www.example.com/index.php/$1 [L,R=301]
Related
I want to create pretty url. But, I got some problem with .htaccess. For example I have url domain/some.php?f=query-string.
I want to change domain/query-string (expected url). Is that possible to change / redirect via .htaccess. Or maybe from php file itsself.
this is a bit of htaccess snippet i made, but i get it blank/error page
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteRule ^/([^/.]+)$ some.php?f=$1 [NC,L]
</IfModule>
Thanks for your attention.
RewriteRule ^/([^/.]+)$ some.php?f=$1 [NC,L]
In .htaccess, the URL-path matched by the RewriteRule pattern does not start with a slash, so the above will never match and it will do nothing. This should be written like the following instead:
RewriteRule ^([^/.]+)$ some.php?f=$1 [L]
The NC flag is not required here, since the regex is already "case-insensitive".
I have this incoming url where the last part is dynamic.
https://www.rishi.com/q/CuYuGy
and want to rewrite the url to below link.
https://rishi.com/test.php
where it gets the dynamic part and performs action
so far i have done this
RewriteCond %{HTTP_HOST} ^rishi.com/q/%{QUERY_STRING}$
RewriteRule ^$ {HTTP_HOST} ^rishi.com/test.php [L,R=301]
please help me resolve it.
Thanks
Try this
RewriteRule ^q/([a-zA-Z0-9-/]+)$ test.php?query_string=$1
RewriteRule ^q/([a-zA-Z0-9-/]+)/$ test.php?query_string=$1
Try this below htaccess code. It should help you
RewriteCond %{REQUEST_URI} ^/q/(.*)$
RewriteRule ^(.*)$ /test.php [L,R=301]
Here is my URL:
http://localhost/school-project/project1/mypage.php/home
I wanna get rid of .php in mypage.php. So the new URL should look like this:
http://localhost/school-project/project1/mypage/home
I have tried to use RewriteRule in .htaccess, but none of them worked!
Here is the code in my .htaccess:
(this one actually gets rid of the .php, but it turned the page to Object not found, error 404)
RewriteRule ^mypage.php/(.*)$ http://localhost/school-project/project1/mypage/$1[NC,L,R]
or
RewriteRule (.*)mypage/(.*)$ /mypage.php?/$1 [L]
I don't really know where the problem is. Any ideas?
Thanks!
Try this :
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+(.*)\.php(.*)\sHTTP.*$ [NC]
RewriteRule ^ /%1%2 [R=302,L,NE]
RewriteCond %{REQUEST_URI} !\.php
RewriteRule ^([^\/]*)/([^\/]*)$ $1.php/$2 [L]
Second & third lines are removing php extension externally.
Forth & fifth to redirect request to original path internally .
Clear browser cache then test , if it is Ok change R=302 to R=301 in order to be permanent redirection .
I found another solution for my problem. Thank you so much for all the help!
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^mypage(/.+)$ mypage.php$1 [NC,L]
Guys I am trying to change my url using .htaccess but getting one problem
My URL looks like this
www.example.com/web-search.php?q=car&limit=15
I want to turn it like that
www.example.com/web/cars/15
but not succeeding I don't get the problem please help me. Thanks
Here is my .htaccess code
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /web-search\.php\?q=(.*)\&limit=(.*?)\ HTTP
RewriteRule ^ /%2/%3? [R=301,L]
RewriteRule ^ web/([^/]*)/([^/]*)$ /web-search.php?q=$1&limit=$2 [L]
It works it I remove "web/" from the rewrite url but then url looks like
www.example.com/cars/15
which I don't want I want to add web/ also. Thanks in advance
Update 1:
This causing the problem it is above the mentioned rewrite rule
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /search\.php\?q=(.*)\&limit=(.*)\&siz=(.*?)\ HTTP
RewriteRule ^ /%2/%3/%4? [R=301,L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)$ /search.php?q=$1&limit=$2&siz=$3 [L]
This is caused by two oversights. The first rule does not add "web" to the url. The second rule contains a rogue space between the ^ and the rest of the regex, causing it to return an error.
RewriteEngine On
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /web-search\.php\?q=(.*)\&limit=(.*?)\ HTTP
RewriteRule ^ /web/%2/%3? [R=301,L]
RewriteRule ^web/([^/]*)/([^/]*)$ /web-search.php?q=$1&limit=$2 [L]
Remember to clear your browser cache before testing this, as your browser might have cached the old, wrong, redirect.
I'm using php switch[_get] in my menu system to create url.com/?p=page and I'd like that to change into url.com/page.html. But I can't make it work, maybe some of you know the right settings for this.
I'm currently using this as .htaccess:
RewriteEngine On
RewriteBase /
Options +FollowSymLinks
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^start(.*)\.html$ ?p=start$
Thank you!
Update:
I tried with the $1 but still the url is: ?p=start when I want it to be /start.html
Looks like you're missing the $1 in your last rule:
RewriteRule ^start(.*)\.html$ ?p=start$1
^^^^
EDIT After new information, try:
RewriteCond %{QUERY_STRING} p=([a-z0-9]+) [NC]
RewriteRule . /%1.html [L]
This captures the p= parameter from the querystring and uses it to rewrite to page.html
Try
RewriteRule ^start(.*)\.html$ ?p=start$1 [L]
See the one (1) at the end.
htaccess works the other way around.
It makes things like /start.html proxy to ?p=start however, you still have make the links themselves target /start.html.
So change all the <a href="?p=start"> to <a href="/start.html">.
you need
RewriteCond %{QUERY_STRING} ^p=(.+)$ [NC]
RewriteRule ^$ /%1.html? [R=301,L]
R=301 is to change the url in the browser, but
you still need to update all links on the site:
<a href="?p=start"> to <a href="/start.html">
Edit: Try the updated one (it has a ? after html)