In Previous my application was single page application. so we used id's in the URLS.
Currently we have changed as seperate pages. but our site URL is in external site. So we have to redirect the URL lines in the htacces file
www.mydomain.com/#news/
to
www.mydomain.com/news/
how to achieve this?
Try using this:
RewriteEngine On
RewriteBase /
RewriteRule ^#/(.*)$ /$1 [L,NC,R]
This should remove the # from your URL. Just make sure you clear your cache before testing this.
Once you're happy that the rewrite is working, you can change R to R=301. Don't do this beforehand.
Related
I have a url which is
www.domain.com/index.php?route=ticketsystem/generatetickets
I want people who type in the url www.domain.com/contact to be redirected to the page index.php?route=ticketsystem/generatetickets however have the url bar still show /contact is that possible via htaccess and if so how? I tried the below
RewriteEngine On
RewriteBase /
RewriteRule contact /index.php?route=ticketsystem/generatetickets [L,QSA]
For your shown attempts, please try following .htaccess rules file. Make sure your index.php and .htaccess files are present in same directory/folder. Also better to use & rather than using / for query string.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^contact/?$ index.php?route=ticketsystem&generatetickets [QSA,NC,L]
I have a subfolder content in:
www.mydomain.com/content
Users can log in at this location. I have also created a page that will directly load a content using a PHP page:
www.mydomain.com/content/direct.php?direct=<contentid>
Users can use the link and share them. However, if the user is not yet authenticated, it should redirect them to the homepage with a message letting them know that they need to log in:
www.mydomain.com/content/index.php?error=4
I wanted to support simple URLS like:
www.mydomain.com/content/direct/<contentid>
However, I am getting too many redirects error. May I know how I should write my HTACCESS file?
Here is the HTACCESS I am using currently placed inside the subfolder /content/:
Options +FollowSymLinks
RewriteEngine On
#direct
RewriteRule ^/?direct/([^/d]+)/?$ direct.php?direct=$1 [QSA]
#SSL
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
The solution I settled with was to put the .HTACCESS file in the root instead of the subfolder with the following code
RewriteRule ^/?content/([^/d]+)/?$ subfolder/content.php?content=$1 [R=301,L]
I used [R=301,L] instead since I prefer that the real URL is visible to the user. I only needed the simple URL for easier means to integrate them into existing platforms that do not like query strings.
In content.php I place a redirect to the login page if the user is not authenticated. This prevented the multiple redirect error.
I have some external sites pointing links (examples below) to my site that are not correct - they need to have .html added to the end. I have tried getting them changed on their side but cant - how can I do it so within .htacess I am manually adding the .html bit onto the urls I want to add it onto?
For example I have:
www.test.com/blue-boxes
and this needs to be www.test.com/blue-boxes.html
I am trying this:
RewriteRule ^(/blue-boxes)/?$ $1.html [L,R=301]
But its not working...any ideas?
This rule should work:
RewriteRule ^blue-boxes/?$ /blue-boxes.html [L,R=301]
if the url is www.test.com/blue-boxes or www.test.com/blue-boxes/ it will redirect to www.test.com/blue-boxes.html
I am serving static content with Amazon CloudFront and am using my servers as the origin.
Since CF does not respect ? query strings, I can't easily force CF to use new versions of .png files. I also need fast invalidation and do not want to pay for invalidation requests.
So I want to create a completely fake directory with .htaccess to force versioning for my images.
For instance, I want:
domain.com/static/0.12/images/background.png
going to
domain.com/static/images/background.png
Where 0.12 is my APP version, which will be automatically changed through my deployment script.
What would be the .htaccess rule for this?
If you actually want the URL
domain.com/static/0.12/images/background.png
to be internally redirected to
domain.com/static/images/background.png
Add the following to the .htaccess file in the root of your site.
RewriteEngine On
RewriteBase /
RewriteRule ^static/0\.12/images/(.+)$ static/images/$1 [L,NC]
If the APP version varies then use
RewriteEngine On
RewriteBase /
RewriteRule ^static/[\.0-9]+/images/(.+)$ static/images/$1 [L,NC]
To force all requests from a URL like
example.com/static/images/background.png
to rewrite to internal URLs like
example.com/static/0.12/images/background.png
Use:
RewriteEngine On
RewriteRule ^static/images/(.*)$ static/0.12/images/$1 [L]
I am using PHP and I need to use a name say "Pranav dave" in url which should redirect me to "myprofile.php" what should i do?.. also the url should display me "Pranav dave".. and what should be the htaccess rule to redirect any html file to php file?
You could make it like this:
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)$ myprofile.php?profile=$1 [NC]
After that, you can use your urls like this http://example.com/Pranav dave. The only problem is, that the browser will rewrite the url, and after that, its looking like followink one http://example.com/Pranav%20dave