I am using the following code to rewrite a url on my website:
RewriteEngine On
RewriteBase /
RewriteRule ^about/organisation$ pages/about/organisation [NC,L]
This hides the "pages" bit of the url, But if the user types in "about/organisation/index.php" they still get to the page and index.php is shown. What I want to do is if they type in the index.php it redirects them to "about/organisation" effectively hiding the file name.
I have tried this but it didnt work.
RewriteRule ^about/organisation$ pages/about/organisation/index.php [NC,L]
What am I doing wrong?
EDIT: from the answers it seems that my server doesnt let me access the relevant files so Ill have to solve that one first
You can use:
RewriteEngine On
RewriteBase /
RewriteRule ^(about/organisation/).+$ $1 [R=302,L,NE,NC]
RewriteRule ^about/organisation/?$ pages/about/organisation [NC,L]
Maybe try your rule like this.
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /about/organisation/([^/]+)
RewriteRule ^ /about/organisation? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
REwriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^about/organisation/?$ pages/about/organisation [NC,L]
Related
I'm in the process of trying to prettify my URLs
From: http://localhost/blog.php?id=1
To: http://localhost/blog/1
I've added the below to my .htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^blog/([a-zA-Z0-9]+)$ blog.php?id=$1 [NC,L]
From my understanding that should now redirect when I call my "to" url in PHP header("location: /blog/".id); it takes me to the relevant page, and my $_GET['id'] should have a value. It's coming up empty
I've been messing around with a few different regular expressions, but I don't think that's the issue.
In the apache config I changed "AllowOverride" to 'All'
To check to see if the .htaccess was even being used I put in some invalid regex, and got an error in apache_error.log
I've been on a ton of different pages asking the same thing, and watched plenty of YouTube vids, but I can't see what I'm missing
Have your htaccess Rules file in following manner. Please make sure to clear your browser cache before testing your URLs.
Options +FollowSymLinks -MultiViews
RewriteEngine On
##Rules for external redirect to blog/1 here.
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{THE_REQUEST} \s/(blog)\.php\?id=(\d+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]
##Rules for internal rewrite to blog.php file here.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^blog/([\w-]+)/?$ blog.php?id=$1 [QSA,NC,L]
##Rules for internal rewrite to index.php file here.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ index.php?id=$1 [QSA,NC,L]
try this .
1.
Options +FollowSymLinks
RewriteEngine on
RewriteRule blog/id/(.*)/ blog.php?id=$1
RewriteRule blog/id/(.*) blog.php?id=$1
example url :- http://localhost/blog/id/1/
Directory Type URL
I am very new to .htaccess files and may have done mine wrong. I have been gathering snippets of code trying to get done what I want.
This is what I have in my file so far
I read this should be in your .htaccess file
Options +MultiViews
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
This was added to force a redirect from HTTP to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This was added to remove .php at the end of all the files
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
This was added to remove the showing of /index when the home link was pressed
RewriteCond %{THE_REQUEST} ^.*\/index?\ HTTP/
RewriteRule ^(.*)index\.php?$ "/$1" [R=301,L]
I have tried a lot of ideas I found on both here and other sites from Google. I have had no luck hiding the GET request.
Currently, the URL looks like https://mysite.ca/event?id=123
What I would like it to look like is either https://mysite.ca/event/123
This is hosted on Godaddy and it is just a plain PHP site if that makes any difference.
Any ideas would be great!
First of all Options +MultiViews already removes .php extension so you don't need:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
About your problem try this Rule:
RewriteRule ^event/([0-9]+)?$ event?id=$1 [NC]
Which changes url from example.com/event/<number> to example.com/event?id=<number>
Although, if your site makes infinite redirects then you should change it to:
RewriteRule ^events/([0-9]+)?$ event?id=$1 [NC]
This happens if you have some includes/headers that redirect back to event and creates infinite loop.
I have link like this for example http://localhost/somepage.php?id=1. And i want to make link like this http://localhost/somepage/1 but not just on somepage.php but for all pages on localhost. Here is my code for hidding .php extension and now i now i got http://localhost/somepage?id=1 and now i need to get http://localhost/somepage/1.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
You can replace your rule with this rule:
RewriteEngine On
RewriteRule ^([^/]+)/(\d+)/?$ $1.php?id=$1 [QSA,L]
I have this .htaccess which basically is supposed to turn my links from
http://www.dsbigiena.ro/products.php?product-id=Colac-wc-cu-folie-de-plastic-cu-actionare-manuala-prin-buton
to
http://www.dsbigiena.ro/Colac-wc-cu-folie-de-plastic-cu-actionare-manuala-prin-buton/
Unfortunately, it's not doing it.
Did I write it wrong?
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]*)/$ /products.php?product-id=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
EDIT: I did indeed test the .htaccess with "deny from all", and it works.
Your current rewrite rule only resolve a pretty URL. It won't convert an actual /products.php URL to the pretty one by itself. You need to have an explicit rule for that as
RewriteEngine On
RewriteBase /
# Redirects from a normal URL to a pretty one
RewriteCond %{THE_REQUEST} \ /products\.php\?product-id=([^\ ]+) [NC]
RewriteRule ^ /%1/? [L,R=301]
# Resolves the pretty URL
RewriteRule ^([^/]+)/?$ /products.php?product-id=$1 [QSA,L]
I want to redirect all http://localhost/webportal/organizations/32 requests to http://localhost/webportal/organizations/32?qt-organization_tabs=tab1#qt-organization_tabs (where 32 is a variable).
How can I do this using mod_rewite?
Update:
I have updated the URLs above, the URLs originally posted were not correct, anyway I tried the following rule and it is not working:
RewriteRule ^/organizations/(.+)$ ^/organizations/$1?qt-organization_tabs=tab1#qt-organization_tabs [L,R]
All the other rules are working properly, here is the relevant part of my htaccess file (Drupal CMS):
RewriteEngine on
RewriteRule "(^|/)\." - [F]
RewriteBase /webportal
RewriteRule ^/organizations/(.+)$ ^/organizations/$1?qt-organization_tabs=tab1#qt-organization_tabs [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]
Thanks
Add this in the htaccess file in your document root:
RewriteEngine On
RewriteRule ^/?webportal/organizations/(.+)$ /pepris/webportal/$1?qt-organization_tabs=tab1#qt-organization_tabs [L,R]
You can also use mod_alias:
RedirectMatch ^/?webportal/organizations/(.+)$ /pepris/webportal/$1?qt-organization_tabs=tab1#qt-organization_tabs