RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L]
But when I'm in my page menu and click "home" I'm redirecting to www.page.com/index.
I want it to be like: www.page.com
You can write rule for index.html file
RewriteRule ^index.html$ http://%{HTTP_HOST}/ [R=301,L]
Related
Homepage TLD resolves fine.
When clicking on subpage link e.g. "mortgages/" the subpage does not display, instead the homepage is displayed, although the pretty URL does display correctly as www.mydomain.co.uk/mortgages/
The subpage will only display if I enter the actual page "mortgages.php" into the menu structure.
So it seems that the subpages are not parsing correctly for some reason.
Could this be an HTACCESS issue?
Have tried various changes to HTACCESS
Current HTACCESS code
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
IndexIgnore *
When clicking on subpage link e.g. "mortgages/" the subpage does not display, instead the homepage is displayed, although the pretty URL does display correctly as www.mydomain.co.uk/mortgages/
I think this is what you want
remove php file extension-e.g. https://example.com/file.php will become https://example.com/file
alternative 1
Options +MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
alternative 2
Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]
I have no idea of URL coding, please help me out.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourdomain.com
RewriteRule (.*) http://yourdomain.com/$1 [R=301,L]
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ users.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ users.php?user=$1
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)$ users.php?user=$1&page=$2
RewriteRule ^([a-zA-Z0-9_-]+)/([0-9]+)/$ users.php?user=$1&page=$2
If you want to do this from php you can use a rewrite rule from your .htaccess file to pass everything to index.php
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
And after that you can get $_SERVER['REQUEST_URI'] that contains the current path (if you want to do something with it) and redirect back to your domain.
header("Location: http://$_SERVER[HTTP_HOST]");
After some help from another question i managed to figure out about .htaccess on my website for Friendly SEO links.
My public_html folder contains those files
index.php
.htaccess
buisnessdetails.php
eventDetails.php
My htaccess so far is this
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)\ (.*)$ /$1-$2 [L,R=301]
RewriteCond %{THE_REQUEST} /eventDetails\.php\?id=(.+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ /eventDetails.php?id=$1&name=$2 [L]
</IfModule>
So when someone clicks an href which has http://sourtouki.gr/123/abc
the htaccess file goes to the
eventDetails.php file.
But now i want it to change like this
i've edited my public_html folder like this
index.php
events(folder)
2.1 eventDetails.php
buisness(folder)
3.1 buisnessdetails.php
So with these changes i want to do the following thing
Changed the href link to
http://sourtouki.gr/events/123/abc
What changes i must do to the .htaccess file so it can understand that if someone pushes the above link, to go to the eventDetails.php which is inside events folder??
And is it going to be editable so i can add also buisness folder inside that rewrite rule?
You can use something like :
RewriteEngine on
RewriteRule ^(.*)\ (.*)$ /$1-$2 [L,R=301]
RewriteCond %{THE_REQUEST} /events/eventDetails\.php\?id=(.+)&name=(.+)\sHTTP [NC]
RewriteRule ^ /events/%1/%2? [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^events/([^/]+)/([^/]+)/?$ /events/eventDetails.php?id=$1&name=$2 [L]
I have links:
mydomain.com/index.php
mydomain.com/index.php?cat=1
mydomain.com/index.php?product=1
mydomain.com/index.php?view=content
mydomain.com/pages.php?view=order
mydomain.com/pages.php?view=register
mydomain.com/price.php
When I enter this links in browser, must get content from that files:
index.php.html
index.php_cat=1.html
index.php_product=1.html
index.php_view=content.html
pages.php_view=order.html
pages.php_view=register.html
price.php.html
How can I modify .htacces file for all this links?
Try this one:
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME}\.php -f
#RewriteRule ^(.*)$ $1.php
RewriteEngine on
# general
RewriteRule ^index.php.html$ index.php
RewriteRule ^pages.php_view=register.html$ pages.php?view=register
Try :
RewriteEngine on
RewriteRule ^index.php\.html$ /index.php [NC,L]
RewriteRule ^price\.php\.html$ /price.php [NC,L]
RewriteRule ^([^.]+)\.php_([^=]+)=([^.]+)\.html$ /$1.php?$2=$3 [NC,L]
Here's what I've currently written in my .htaccess file:
RewriteEngine on
RewriteRule ^contact contact.php
RewriteRule ^browse browse.php
RewriteRule ^contact/ contact.php
RewriteRule ^privacy privacy-policy.php
RewriteRule ^signup register.php
RewriteRule ^register register.php
So when a user requests http://mydomain.com/welcome, which is not defined in the .htaccess file, it will result in a "404 Not Found" page.
Instead, I'd like to redirect pages that aren't explicitly defined in the .htaccess to another script, and pass the original URL. I don't want to use ErrorDocuments here. How can I do this?
RewriteEngine on
RewriteRule ^contact contact.php
RewriteRule ^browse browse.php
# why is contact the only one with a slash at the end?
RewriteRule ^contact/ contact.php
RewriteRule ^privacy privacy-policy.php
RewriteRule ^signup register.php
RewriteRule ^register register.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /other.php [L]