This is what I have so far, its not working as I'd hoped:
RewriteEngine On
RewriteRule ^(.*)$ /index.php?id=$1/ [L]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]
Basically I want to remove index.php everywhere, and in a directory I want to edit a query string also, like so:
https://example.com/directory/?id=Test
Should be:
https://example.com/directory/Test/
Is this possible?
You need to use the RewriteBase directive.
I've got it working here for you: https://mi-linux.wlv.ac.uk/~in9352/directory/5
Here's what I have in my .htaccess:
RewriteEngine On
RewriteBase /~in9352/directory/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/?id=$1 [L]
Obviously you don't need the "~in9352"
Here's the documentation: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
Related
I have a domain example.com i want to redirect it to example.com/public but /public folder should hide from the url.
I am using the below code in .htaccess to redirect, but unable to hide the folder name
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ public [L]
Please help me out for this issue.
You can try this
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(public)
RewriteRule (.*) /public/$1
This should be your complete .htaccess:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+dirname/([^\s]+) [NC]// here you write your directory
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (?!^dirname/)^(.*)$ /dirname/$1 [L,NC]
try this
RewriteEngine On
RewriteRule (.*) public/$ [QSA,L]
My SSL only covers swellnomore.com, not www.swellnomore.com.
I get a security error when i type https://www.swellnomore.com. Can this be fixed (forwarded to https://swellnomore.com ?
I had tried putting the following to htacess but did not helped too
# Override GoDaddy defaults that inhibit URL rewriting
Options -MultiViews
rewriteEngine On
# Rewrite URLs to remove www from domain name
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Before putting the above , htaccess looked like this
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteEngine On
RewriteBase /
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteCond %{HTTP_HOST} ^swellnomore.com$
RewriteRule ^/?$ "https\:\/\/swellnomore\.com\/" [R=301,L]
P.S , I had already changed the site domain to
https://swellnomore.com in wp dashboard > general settings.
If you rewrite the domain , you should rewrite to https not to http
Try this rewrite rule:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
whole htaccess file
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
</IfModule>
# END WordPress
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
Yes, it is possible. You just have to put this .htaccess in your root folder :
RewriteEngine On
RewriteBase /
RewriteRule ^/?$ http://sub.domain.com/this [L]
try this javascript
<script type='text/javascript'>
if(history.replaceState) history.replaceState({}, "", "/");
</script>
Note : where / is the path u want to show.
it shows the url like mysite.com no matter which link i have clicked. but i have a problem with this code while reloading the page the complete url with query string blink into address bar.
Update
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
Example: http://www.addondomain.com/projects/a/gallery/4/2 -> http://addondomain.com/projects/a/gallery/4/2
Maybe this will help you:
Add this to your .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
I have an issue I can't seem to debug. I have tried many solutions and no luck.
When I access a URL with subfolder/index.php I get redirected back to the root page. If I access another page in that subfolder it works fine. I am not sure what is causing this on my code. Here is what I have.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.domain\.com
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]
# remove index
RewriteRule (.*)index$ $1 [R=301]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]
Any suggestions? Thanks!
Keep your rules like this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L,NE]
RewriteCond %{HTTP_HOST} ^www.domain\.com
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule ^(.+?)/$ $1 [R=301,L,NE]
# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1.php [L]
I am trying to just update my .htaccess file so that I get nicer looking url's (without the file extenstion of .php). The file already has a redirect in it as I have both domain names.
Here is the original code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^darrenmorton\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.darrenmorton\.com$
RewriteRule ^/?$ "http\:\/\/darrenmorton\.co\.uk\/" [R=301,L]
And here is my updated code that is not working
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^darrenmorton\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.darrenmorton\.com$
RewriteRule ^/?$ "http\:\/\/darrenmorton\.co\.uk\/" [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
Not
RewriteCond %{REQUEST_FILENAME} \.php -f
RewriteRule ^(.*)$ $1.php [L]
RewriteRule ^contact-darren-morton.php$ contact-darren-morton.php [L]
Not sure what is the problem as I am new to .htaccess files!
You can use:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?darrenmorton\.com$ [NC]
RewriteRule ^ http://darrenmorton.co.uk}%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{THE_REQUEST} \s/+(?:index)?(.*?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]
You are redirecting everything with that statement:
RewriteRule ^/?$ "http\:\/\/darrenmorton\.co\.uk\/" [R=301,L]
Nothing after that will ever work, because it is the last rule to be checked if it matches (and it matches always). Defined by you with the [L].
So at least you need to change the order of your rules. If you want the rules to only work on your .co.uk domain you have other options, too.
Simplified Question
I changed domain.com/folder/client.php?id=1 to 1.domain.com with this .htaccess code
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+).domain.com$ [NC]
RewriteRule ^$ /client.php?id=%2 [QSA,NC]
Now I want to change domain.com/folder/about.php?id=1 to 1.domain.com/about.
Is it possible ? or is there any other ways to do this?
Thank you :D
Old Question
In my directory, I have 2 pages (client.php, about.php). I've already set a wildcard subdomain to the page directory and changed domain.com/folder/client.php?id=1 to 1.domain.com. This is my .htaccess code :
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+).domain.com$ [NC]
RewriteRule ^$ /client.php?id=%2 [QSA,NC]
Now, I need to add another page. So, in client.php page, there's a button to go to about.php page in the same directory. I tried 1.domain.com/about.php and it's not working.
Do I have to create another line of RewriteCond ? or is there any other ways to do this?
Thank you very much :D
Updated Code without working id
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+).domain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/about [NC]
RewriteRule ^$ /client.php?id=%2 [QSA,NC]
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?([^.]+)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/about [NC]
RewriteCond %{REQUEST_URI} !about\.php [NC]
RewriteRule . /about.php?id=%1 [L,QSA]
**The code resolved the text in url box. Let's say id=1. Now it's showing 1.domain.com/about.
the php code : `$_GET["id"]` is not specified.**
Thanks to faa for the edit :D
The Full Solution
Refer Using mod-Rewrite with 5 pages (wildcard sub-domain)
You may try this:
Options +FollowSymLinks
RewriteEngine on
## This is the actual rule-set that works as it is according to the OP
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([^.]+).domain.com$ [NC]
# Added to exclude folder `/about`
RewriteCond %{REQUEST_URI} !^/about [NC]
RewriteRule ^$ /client.php?id=%2 [L,QSA,NC]
## This is the additional rule set
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?([^.]+)\.domain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/about [NC]
RewriteCond %{REQUEST_URI} !about\.php [NC]
RewriteRule . http://domain.com/folder/about.php?id=%1 [L,QSA]
Maps silently
http://N.domain.com/about with or without trailing slash
To:
http://domain.com/folder/about.php?id=N
For permanent and visible redirection, replace [L,QSA] with [L,R=301,QSA]