So I'm trying to turn my website from this:
http://profe5.com/Profe5-Web/public_html/login.html
To this:
http://profe5.com/login
I've been struggling to do this, but whenever I run it I get 404 error!
This is my htaccess:
DirectoryIndex Profe5-Web
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^profe5\.com$ [NC]
RewriteRule ^(.*)$ http://profe5.com/$1 [R=301,L]
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [R=301,L]
RewriteRule ^Profe5-Web/public_html/(.*)$ $1 [R=301,L]
It would be so awesome if you guys could help me!
Thanks so much!
This should be your complete .htaccess:
DirectoryIndex Profe5-Web
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^profe5\.com$ [NC]
RewriteRule ^(.*)$ http://profe5.com/$1 [R=301,L]
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+Profe5-Web/public_html/([^.]+)\.html [NC]
RewriteRule ^ %1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^/.]+)/?$ Profe5-Web/public_html/$1.html [L,QSA]
you might consider instead doing this via a virtual host; check with your hosting company about setting it up
If you want /login to map to Profe5-Web/public_html/login.html - try this:
RewriteRule ^([^.]+)$ Profe5-Web/public_html/$1.html [R=301,L]
The RewriteRule you already have, RewriteRule ^([^\.]+)$ $1.html [R=301,L] will map /login to /login.html, which doesn't seem to do what you need it to.
Related
folks!
I have an PHP application runing on Apache2 in localhost. The system uses friendly URL from $_SERVER['REQUEST_URI']. My .htaccess:
RewriteEngine On
#RewriteRule ^(.*)$ https://myapp.localhost/$1 [R=permanent]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
RewriteRule ^$ index.php?/ [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?/$1 [QSA,L]
If I comment lines 3 and 4, the system run ok. If I use the code as I show you, he write URL as https://myapp.localhost/index.php?/ where it needs to write https://myapp.localhost/. SSL Certified it's ok.
Images and archives can't be found with this configuration, but without lines 3 and 4 and using https manually it's showed.
Thank you for your cooperation.
Sorry, the last message i answer in portuguese, Mr. #Martin.
Maybe the problem was use more than one tutorial. After so much searchs. I understand: it was necessary delete some lines of code at /etc/apache2/sites-available/bigpecasnew-localhost-ssl.conf and add this lines at <Directory /home/user/site>SSLOptions +StdEnvVars</Directory> as I read in
https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-18-04.
After I change my code on .htaccess:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
RewriteRule ^$ index.php?/ [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?/$1 [QSA,L]
So that works.
Thank you for your cooperation.
I would like redirect http://example.com/index.php?a=music to http://example.com/music (where the number is a variable/dynamic). My site is http : / / example . com
I added the following line to my mod-rewrite rules in my .htaccess file:
RewriteRule ^index\.php$/?/a/=(.*)$ http://example.com/index.php?a=$1 [L,R=301]
However, it doesn't seem to work. I know I'm doing something wrong, I'm just not sure how to fix it. Any help is appreciated.
Best,
Jeff
Edited:
Thanks Tom,
This is what I have:
Rewritecond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
This should work:
RewriteRule ^(.*)$ /index.php?a=$1 [L]
RewriteEngine On
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
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]
This is how my current .htaccess looks like at the moment. Line 3 and 4 I took from another question at stackoverflow, and the rest simply removes the .php file extension. But the redirect to https part isn't working. Any ideas?
EDIT:
I just figured out that the problem is in my site's .conf file in the sites-enabled folder of apache. I need a separate block for the :80 and :443 port, which I can't figure out how to do, but that's a topic for another question.
The following is what I use to enforce https, hope it will be of use.
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]
You can try this for redirect on https:
RewriteRule ^(.*)$ https://www.%1.%2/$1 [L,R=301]
The Following code may Works.
Url:- home
RewriteRule ^home$ index.php?page_slug=$0 [QSA]
RewriteRule ^home/$ index.php?page_slug=$0 [QSA]
This is URL- page/new
RewriteRule ^page/([a-zA-Z0-9-/]+)$ page.php?page_slug=$1 [QSA]
RewriteRule ^page/([a-zA-Z0-9-/]+)/$ page.php?page_slug=$1 [QSA]
You can use the following code to redirect from http to https :
RewriteCond %{HTTPS} ^off$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R]
i want change this URL:
domain.com/directory/news?id=80&title=news-title
to this:
hdomain.com/directory/news/news-title
how can I do this?
my htaccess also has a lot other rewrites. look:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /directory/
RewriteRule ^referenzen/([^.]+)/$ $1.php?rw=1 [QSA,L]
RewriteCond %{QUERY_STRING} !^rw=1
RewriteRule ^brands.php$ http://domain.com/directory/referenzen/brands/$1 [R=301,L]
RewriteRule ^referenzen/([^.]+)/$ $1.php?rw=1 [QSA,L]
RewriteCond %{QUERY_STRING} !^rw=1
RewriteRule ^entertainment.php$ http://domain.com/directory/referenzen/entertainment/$1 [R=301,L]
RewriteRule ^referenzen/([^.]+)/$ $1.php?rw=1 [QSA,L]
RewriteCond %{QUERY_STRING} !^rw=1
RewriteRule ^tourism.php$ http://domain.com/directory/referenzen/tourism/$1 [R=301,L]
RewriteCond %{THE_REQUEST} index(\\.php)?
RewriteRule ^index(\\.php)?$ http://domain.com/directory/ [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
I don't know if it's all correct but it is doing what it should do. ;-)
I only need the new rule to rewrite the dynamic url for the news.
Hope anyone can help - thanks!
You can rewrite all links to one php file and with reg. load templates that you need. I can help you.
This url
example.com/videos/load.php?cat=video-category
would become
example.com/videos/video-category
Also, there is pagination and limit url
example.com/videos/load.php?cat=video-category&p=2&limit=20
and it would become
example.com/videos/video-category?page=2&limit=20
this url also work
example.com/videos/video-category?page=2
example.com/videos/video-category?limit=20
Here is my htaccess (into videos folder)
Options +FollowSymLinks
RewriteEngine on
RewriteBase /videos/
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NE,L]
RewriteRule ^([^/]+)/?$ load.php?cat=$1 [L,QSA]
RewriteRule ^([^/]+)/page/?$ $1 [R=301,L]
RewriteRule ^([^/]+)/page/([1-9][0-9]*)$ load.php?cat=$1&p=$2 [L,QSA]
how to do this.. plz help me.. thanks..
Think maybe you're looking for something like this?
Options +FollowSymLinks
RewriteEngine on
RewriteBase /videos/
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,NE,L]
RewriteCond %{THE_REQUEST} \ /+videos/load\.php\?cat=([^&\ ]+)&?([^\ ]*)
RewriteRule ^ %1?%2 [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ load.php?cat=$1 [L,QSA]
That satisfies the question you're asking, but your rules have stuff for /page/, which isn't part of your question at all.