I want to rewrite the URL like below:
URL: http://localhost/my_site/?file_name=sample
This is my URL I want to show it like:
URL: http://localhost/my_site/sample
that means I want to remove file_name parameter and get the parameter value and set it in URL, for setting this I have used below code:
RewriteEngine On
RewriteBase /my_site/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /?file_name=$1 [QSA,L]
But its not working, when I type http://localhost/my_site/sample its showing me the list of all sites present in my local that means its taking me to http://localhost instead of require page. What wrong I am doing?
Please help, Thanks in advance
Assuming that mysite folder is under DocumentRoot. add this to your
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !\.\w+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) /$1/ [R,L]
RewriteCond %{REQUEST_URI} ^/(my_site)/([\w\d-]+)/$ [NC]
RewriteRule ^ %1/?file_name=%2 [L,QSA]
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} (?:(.*)&)?file_name=([\w\d-]+)(.*) [NC]
RewriteRule ^(my_site) $1/%2/?%1%3 [L,R]
For server side:
RewriteCond %{REQUEST_URI} ^/([\w\d-]+)/$ [NC]
RewriteRule ^ /?file_name=%1 [L,QSA]
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{QUERY_STRING} (?:(.*)&)?file_name=([\w\d-]+)(.*) [NC]
RewriteRule ^ %2/?%1%3 [L,R]
try this, if it works:
RewriteEngine On
RewriteBase /my_site/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ file_name=/$1 [L]
caution: untested
Related
I have the following:
RewriteEngine On
RewriteCond %{QUERY_STRING} !embed=true [NC]
RewriteRule ^/?wiki/old-page$ /wiki/new-page [L,R]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteRule ^(.*)$ %{DOCUMENT_ROOT}/wiki/index.php [L]
However, when I go to
/wiki/old-page
instead of redirecting to
/wiki/new-page
it redirects to
/wiki/Old-page
What am I doing wrong? Thank you in advance.
I would like to know if this final result can be achieved with some htaccess rules.
On the config folder. Where * is the page's name to show as folder.
/projectdir/config/?p=* or /projectdir/config/index.php?p=*
to /projectdir/config/*/
Example
/projectdir/config/?p=page1 => /projectdir/config/page1/
/projectdir/config/index.php?p=page1 => /projectdir/config/page1/
I tried the code posted in this question, but without results
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w\d~%.:_\-]+)$ index.php?p=$1 [NC]
Which basically: http://localhost/index.php?page=controller To
http://localhost/controller/
You can use this code in /project/config/.htaccess:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /project/config/
RewriteCond %{THE_REQUEST} /config/(?:index\.php)?\?p=([^\s&]+)&p2=([^\s&]+)\s [NC]
RewriteRule ^ %1/%2? [R=301,NE,L]
RewriteCond %{THE_REQUEST} /config/(?:index\.php)?\?p=([^\s&]+)\s [NC]
RewriteRule ^ %1? [R=301,NE,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?p=$1&p2=$2 [L,QSA]
RewriteRule ^([^/]+)/?$ index.php?p=$1 [L,QSA]
I dont know much about htaccess files and i was hoping you can help me.
I have this file:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?d-hive.net$
RewriteCond %{REQUEST_URI} !^/d-hive/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /d-hive/$1
RewriteCond %{HTTP_HOST} ^(www.)?d-hive.net$
RewriteRule ^(/)?$ d-hive/index.php [L]
I was wondering how can i force the page to open up the HTTPS protocol instead of the HTTP protocol.
use full url e.g.
RewriteRule ^(/)?$ https://www.d-hive.net/index.php [L]
Plus, can include
RewriteCond %{HTTPS} =on [NC]
so something like,
RewriteCond %{HTTPS} =on [NC]
RewriteRule ^(/)?$ https://www.d-hive.net/index.php [L]
You can have your rules like this. Let me know how this works for.
RewriteEngine on
RewriteCond %{HTTPS} !^on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?d-hive\.net$
RewriteCond %{REQUEST_URI} !^/d-hive/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /d-hive/$1
RewriteCond %{HTTP_HOST} ^(www\.)?d-hive\.net$
RewriteRule ^(/)?$ d-hive/index.php [L]
I am trying to rewrite the url example.com/parts/toolbucket/part.php?id=1 into example/toolbucket/part/1
I have most of the .htaccess working but the last part of the rewrite doesn't work.
This is my .htaccess
Options -Indexes
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} \s/parts/([^\s]+)\s [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /parts/$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
RewriteRule ^toolbucket/([0-9]*)$ ./part.php?id=$1
Any ideas?
Because you are missing the directory part in the rule. If you want your URL to be this example.com/toolbucket/part/1
Replace this
RewriteRule ^toolbucket/([0-9]*)$ ./part.php?id=$1
With this.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^toolbucket/part/([0-9]*)/?$ /parts/toolbucket/part.php?id=$1 [L]
I have the following rules:
RewriteCond %{REQUEST_URI} !script.php
RewriteCond %{QUERY_STRING} url=(.*)
RewriteRule .* script.php?q=%1
RewriteCond %{REQUEST_URI} !script.php
RewriteRule (.*) script.php?q=$1
What I'm trying to accomplish here is that every access to http://example.com/?url=www.google.com is redirected to script.php?q=www.google.com and if there is no query string, relative path should be sent to script.php, for example in http://example.com/path, should be redirected to script.php?q=path. This doesn't seem to work with my rules, but I'm not sure why. Is this even possible ?
You can have your rules as this:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^url=([^&]+) [NC]
RewriteRule ^/?$ script.php?q=%1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.+)$ script.php?q=$1 [L,QSA]