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>
Related
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]
I am having a hard time trying to drop the .html for our newly updated website through .htaccess. I have tried a number of different lines of code copy and pasted from the internet, but I'm sure it's something simple that I just don't have the experience to see!
In short, I want to make this request (which is a 404) drop the .html:
http://mysite/cmt-grooving-sblade.html
To this:
http://mysite/cmt-grooving-sblade
Any help you could give will be I will be very grateful for!
So far, my .htaccess looks like this. The first section was already there, the rest is my recent attempt.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{REQUEST_URI} \.html$
RewriteRule ^(.*)\.html$ $1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
You can use this to remove .html from your URLs:
RewriteEngine on
RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
It will leave you with your desired URL: http://mysite/cmt-grooving-sblade. Make sure you clear your cache before testing this.
Try this;
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
I am trying to set 2 rules:
if I type http://www.mydomain.it/notizie/LeDelizieDiCasa, htaccess has to load http://www.mydomain.it/?rssfeed=LeDelizieDiCasa page
www.mydomain.it/categoria/Cucina htaccess has to load http://www.mydomain.it/?categoryfeed=Cucina
I tried:
RewriteCond %{REQUEST_URI} ^/?rssfeed=Cucina
RewriteCond %{HTTP_HOST} ^(www.)?mydomain.it$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.it/categoria/Cucina [R,L]
but it doesn't work, and if I go to http://www.mydomain.it/categoria/Cucina I have error 404 returned.
Who can help me?
mycurrent .htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
#rule 1
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.it$ [NC]
RewriteRule ^notizie/([^/]+)$ /?rssfeed=$1 [L]
#rule 2
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.it$ [NC]
RewriteRule ^categoria/([^/]+)$ /?categoryfeed=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Thank you so much
It's difficult to help you, because I don't see your question or your problem...
I don't know why you add the www. or not.
1) Redirect notizie/LeDelizieDiCasa to http://www.mydomain.it/?rssfeed=LeDelizieDiCasa with:
RewriteRule notizie/LeDelizieDiCasa/? http://www.mydomain.it/?rssfeed=LeDelizieDiCasa [NC,L]
2) Redirect /categoria/Cucina to http://mydomain.it/?categoryfeed=Cucina:
RewriteRule categoria/Cucina/? http://www.mydomain.it/?rssfeed=LeDelizieDiCasa [NC,L]
Add that before #rule 1.
Ask, if it's not that...
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>
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]