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]
Related
I have a web site working on localhost for now.
I send some data with get method to another controller
When I send data my url is look like:
http://localhost/book/Control/?kolon=&satir=unknown&modals=infox&bookid=4555
but i want to it look just like:
http://localhost/book/4555
I tried editing my .htaccess file like below but it does not work:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*)$ Control/?kolon=&satir=unknown&modals=infox&bookid=$1 [L]
</IfModule>
how can I fix it?
You want the pretty URLs through htaccess.
The following is tested and works works:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^book/(\d+)*$ ./book/Control/?kolon=&satir=unknown&modals=infox&bookid=$1
Refer: https://code.tutsplus.com/tutorials/using-htaccess-files-for-pretty-urls--net-6049
Try to change it in that way:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^book/(.*)$ Control/?kolon=&satir=unknown&modals=infox&bookid=$1 [L,QSA,NC]
If bookid it's a numeric value you can use:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^book/([0-9]+)$ Control/?kolon=&satir=unknown&modals=infox&bookid=$1 [L,QSA,NC]
So want to accomplish(with .htaccess) that that I can rewrite this url:
index.php?controller=ControllerName&method=MethodName&view=ViewName&key=value&key2=value2
To this:
/ControllerName/MethodName/ViewName/?key=value&key2=value
This is the code i have now:
RewriteEngine On
RewriteRule ^(.*)/(.*)/(.*)/(.*) index.php?controller=$1&method=$2&view=$3&$4=$5 [L]
RewriteRule ^(.*)/(.*)/(.*)/ index.php?controller=$1&method=$2&view=$3 [L]
Try this rule,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/$ index.php?controller=$1&method=$2&view=$3 [QSA,L]
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>
I have the following .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^project/([0-9]+)/([a-zA-Z0-9]+)/(.+)?$ project.php?id=$1&pName=$2&urlPram=$3 [L,NC]
</IfModule>
when my url format is something like:
mysite.com/project/1/test/vw
everything works fine. But I would also like when the url is typed in the other format, to be rewritten to the first format.
i.e. When I type the url like this:
mysite.com/project.php?id=1&pName=test&urlParam=vw
I wants it to be turned into:
mysite.com/project/1/test/vw
Do I have to write another rule? or is it accomplished in some other way?
The current rewrite rule would not handle both the cases. Add the below rewrite rule as well.
RewriteEngine On
RewriteBase /mysite/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^project/([0-9]+)/([a-zA-Z0-9]+)/(.+)?$ project.php?id=$1&pName=$2&urlParam=$3&no-redir [L,NC,QSA]
RewriteCond %{QUERY_STRING} !no-redir
RewriteCond %{QUERY_STRING} (^|&)id=([^&]+)&pName=([^&]+)&urlParam=([^&]+)
RewriteRule ^project\.php$ project/%2/%3/%4? [R=301,L,NC]
You need one more external redirect rule. Use this code:
<IfModule mod_rewrite.c>
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} /project\.php\?id=([^&]+)&pName=([^&]+)&urlPram=([^&\s]+) [NC]
RewriteRule ^ project/%1/%2/%3? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^project/([0-9]+)/([a-zA-Z0-9]+)/(.+)?$ project.php?id=$1&pName=$2&urlPram=$3 [L,NC,QSA]
</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]