I given htaccess like this
Options +FollowSymlinks
RewriteEngine On
RewriteBase /xxx/folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /xxx/folder/index.php [L]
RewriteRule ^(.*)$ index.php?page=$1 [L]
but giving the url like this
http://domain.com/faq
I get the page variable as index.php. I want to get faq in $_GET['page'].How can i get this?
Remove
RewriteBase /xxx/folder/
Modify
RewriteRule ^(.*)$ index.php?page=$1 [L]
to
RewriteRule ^(.*)$ xxx/folder/index.php?page=$1 [L]
Related
Can any experts in .htaccess tell me why this isn't working? (it's the last line that is key - the .png.webp to png rewrite) Please help!
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^www.test.com [NC]
RewriteRule ^(.*)$ https://test.com/$1 [L,R=301]
RewriteRule ^(.*)\.webp.png$ $1.png [L,R=301]
Example issue:
https://centiqsap.com/wp-content/uploads-webpc/uploads/2020/07/Group-13-min-2.png.webp
Needs to rewrite and redirect to
https://centiqsap.com/wp-content/uploads-webpc/uploads/2020/07/Group-13-min-2.png
Have your htaccess file like this way once(I have added new rule and kept OP's old rules too in rules file). Please make sure you clear your cache before testing your URLs. I have also fixed some minor issues, like your https redirection rule should be at very first and you should exacpe .(dots) in regex too.
RewriteEngine ON
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.test\.com [NC]
RewriteRule ^(.*)$ https://test\.com/$1 [NE,L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^(.*\.png)\.webp/?$ $1 [R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.webp -f
RewriteRule ^(.*)/?$ $1.webp [NC,L]
I want my URL to look like this:
https://example-test.example.com/example-application_1.1/index.php?page=pagename&action=actionname
But the user should only type:
https://example-test.example.com/example-application_1.1/pagename/actionname/
Is it possible to make this run with a RewriteRule in .htaccess? I couldn't figure it out.
My .htaccess-file looks like this at the moment:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^example-test\.example\.com
RewriteRule ^example-application_1\.1/([^/]+)/([^/]+)/?$ /example-application_1\.1/index.php?page=$1&action=$2 [QSA,L]
I did it:
RewriteEngine On
RewriteRule "^([^/]+)/([^/]+)/([^/]+)" index.php?page=$1&action=$2&$3 [L]
RewriteRule "^([^/]+)/([^/]+)/" index.php?page=$1&action=$2 [L]
So if the user types in this:
https://example-prefix.example.com/pagename/actionname/id=123&category=456
The URL will be turned into this:
https://example-prefix.example.com/index.php?page=pagename&action=actionname&id=123&category=456
If you still want to have access on your files simply do this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)/([^/]+)" index.php?page=$1&action=$2&$3 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)/" index.php?page=$1&action=$2 [L]
RewriteEngine on
RewriteRule ^example-application_1.1/([^/]*)/([^/]*)/$ /example-application_1.1/?page=$1&action=$2 [L]
This should work.
In index.php, you can get variable: $_GET['page'] & $_GET['action'].
I think you can use:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule "^([^/]+)/([^/]+)" index.php?page=$1&action=$2 [L]
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
RewriteRule ^tags tags.php [L,NC]
</IfModule>
i want to add new page .but write page not found. why? please help me.
RewriteRule ^tags tags.php [L,NC] // i want this www.example.com/tags open tags.php ?
You need to reorder your htaccess rules like this :
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteRule ^tags/?$ tags.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
The problem is that, your rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
Rewrites any request (not a true file/dir) to index.php. since /tags is not an existent file on your directory, so a request for http://example.com/tags was being rewritten to /index.php and the last rule(s) never executed.
I'm using MVC with PHP and, for example, I have this URL:
domain.com/{modue}/{action}
This will make it look like:
domain.com/user/join
I want it to show
domain.com/join
instead.
Can anyone help me?
I tried this with an .htaccess file, but I couldn't. This is my code:
RewriteEngine On
RewriteRule ^$ ./controller.php [L]
RewriteRule ^([a-zA-Z_0-9-]+)/$ /$1? [R=301,L]
RewriteRule ^([a-zA-Z_0-9-]+)$ /controller.php?modulo=$1&%{QUERY_STRING} [L]
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)/$ /$1/$2? [R=301,L]
RewriteRule ^([a-zA-Z_0-9-]+)/([a-zA-Z_0-9-]+)$ ./controller.php?modulo=$1&action=$2&%{QUERY_STRING} [L]
Try this if you have just one controller -
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1
RewriteRule ^(.*)$ user/$1 [L]
</IfModule>
How can I change my URL from domain.com/sprekers/?spreker=value to domain.com/value with a rewrite rule with wordpress.
I've tried to change it like this
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
than I tested it with the htaccess tester http://htaccess.madewithlove.be If I test it on the tester everything works fine but when I do this on my wordpress site it doesn't work. This is my complete htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
</IfModule>
I think it doesn't work because the /sprekers is already "made" by wordpress how can I fix this?
Cheers
Robin
I think, you need to put your first code after the RewriteBase / rule.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>