I'm having an issues with mod rewrite displaying the link in the browser correctly
I have always put links on my pages like this
http://domain.com/contact-us.html
and then use this in my .htaccess file
Options FollowSymLinks
RewriteEngine On
RewriteRule ^([^.]+)\.html$ http://domain.com/index.php?h=$1 [L]
I request the h variable on the index.php page to get and use the slug "contact-us"
$h = htmlspecialchars($_REQUEST['h'], ENT_QUOTES, 'UTF-8', false);
$h = preg_replace('/[^-a-z0-9_]/i','',$h);
This has always worked fine and will still show the domain.com/contact-us.html in the browser
I loaded a site on 1 and 1 and instead of seeing domain.com/contact-us.html I see domain.com?h=contact-us in the browser. Everything is working except it is not showing the link correctly
Got it but for those it may help in the future. First clear your cache with each test
Options FollowSymLinks
RewriteEngine On
RewriteRule ^([^.]+)\.html$ /index.php?h=$1 [L]
Don't include the domain. In my case the website was up one level in the public_html folder so I thought I had to include the domain.
added
RewriteBase /
Works great, final code
Options FollowSymLinks
RewriteEngine On
RewriteBase /
Options FollowSymLinks
RewriteEngine On
RewriteRule ^([^.]+)\.html$ /index.php?h=$1 [L]
Related
I've tried almost every possible option with .htaccess file in my lumen's public folder but non of them are giving me Pretty URLs.
In previous versions of Lumen I hadn't touched any of the .htaccess rules and yet everything used to work perfectly with the shipped default .htaccess file.
But in this new version 5.2 nothing seems to work.
the default is as follows :
# Apache configuration file
# http://httpd.apache.org/docs/2.2/mod/quickreference.html
# Note: ".htaccess" files are an overhead for each request. This logic should
# be placed in your Apache config whenever possible.
# http://httpd.apache.org/docs/2.2/howto/htaccess.html
# Turning on the rewrite engine is necessary for the following rules and
# features. "+FollowSymLinks" must be enabled for this to work symbolically.
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Any thoughts ?!
In you apache config file (httpd.conf or apache2.conf) you must change the "AllowOverride" to "All":
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
I know very little about symfony framework. I copied a website www.example.net to www.example.com site works with url www.example.com/www/app.php or even with www.example.com/www/ but I want it to redirect automatically to app.php without showing it in the url. My htaccess in the www (web) directory is as follows:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
<IfModule>
It doesn't redirect.
Thanks
In your Vhost:
Change this line (Directory section):
AllowOverride None
to:
AllowOverride All
Instead of that rule can you try:
RewriteBase /www/
RewriteRule ^((?!app\.php).*)$ app.php/$1 [NC,L]
Sorry I can't test with Symphony as I am not near my home computer.
A bit late to this game but I just found an Apache directive that saves so much time and makes your htaccess cleaner. The only caveat is you must have Apache 2.2.16+. To have all urls except valid files (images, etc) use app.php as a front controller use the FallbackResource directive.
<Directory "/web/symfony-project">
FallbackResource /app.php
</Directory>
I'm trying to have htaccess work on codeigniter project but the module is not working and I don't know how to enable rewrite module. To have read the htaccess. The OS is Opensuse 12.2.
I have this directive in the default-server.conf
Alias /safememoirs/ /home/gabriele/Web/safememoirs/
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
But I don't understand
A) how to enable the module
B) Where should I put the .htaccess directive id in the default-server.conf or in the site directory?
C) This is for the localhost, what happen when I go online?
I didnt understand exactly what your question was, but here is my htaccess file for removing the index.php in the url.
it should be place in the root folder.
RewriteBase /
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|bjs|plugins|css|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
I want to make a redirect (using .htaccess) to an external site that host where my app can be downloaded so I can give users a url to server.com/install but when I add
Redirect 301 / http://google.com/ to my install directory it redirects to http://google.com/install which is not what I want.
How can I accomplish this with htaccess?
Redirect automatically appends anything from the original URL to the new URL.
Give this a try:
Options FollowSymLinks
RewriteEngine On
RewriteRule ^/ http://google.com [L,R=301]
One more attempt, I added the RewriteBase and wildcard to match all. But I think the problem was that there was no trailing / after google.com. Maybe someone else will answer if this doesn't work.
Options FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://google.com/ [L,R=301]
Ok I have a script in the folder 'intake'. The index.php file auto creates a list of urls. Those urls are in the format:
/intake/4/Westrop
I have an .htaccess file in the intake folder. I want it to redirect the url to a FILE.
The above example would then become /intake/redirect.php?id=4&name=Westrop
Here's what I have so far:
DirectoryIndex index.php
Options All -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)/(.*)$ /intake/redirect.php?id=$1&name=$2 [L]
</IfModule>
But for some reason if I type /intake or /intake/index.php I get a 404 error. According to firebug its trying to take "intake" and turn it into "intake.php"
Any ideas?
Place the following code in .htaccess file in website root folder:
RewriteEngine On
RewriteRule ^intake/(\d+)/([a-z0-9\-_]+)$ /intake/redirect.php?id=$1&name=$2 [NC,QSA,L]
P.S.
Do not use this sort of pattern -- ^(.*)/(.*)$ -- in your case for longer URLs it will work not as you would expect. It will match your URL .. but in a wrong way.
Start your .htaccess with this option:
Options +All -MultiViews -Indexes