URL Rewriting not working (ubuntu13.10/apache2.4.6) - php

I need your help! (sorry for my bad english)
I try to do url rewriting in my localhost on Ubuntu13.10/Apache2.4.6 ...
I searched a lot of time on internet and problem is always here..
this is my .htaccess (I begin in url rewriting so I don't know if it's ok) :
RewriteEngine On
AllowFromAll All
RewriteRule home/ index.php?uc=home
and when I go to 127.0.0.1/mywebsite/home/ I have a 404 error.
My .htaccess is in : mywebsite/.htaccess
I activated url rewrite with "sudo a2enmod rewrite" and restarted apache.
I have no error in apache logs
I read solution who said I have to change AllowOverride to On in /etc/apache2/sites-available/default but I dont have /etc/apache2/sites-available/default file
I am lost...
Please, I don't know what to do...
After many tests : I think I have a problem of AllowOverride

You either need to specify the RewriteBase
RewriteBase /mywebsite/
RewriteRule home index.php?uc=home [L]
or add it to your rule
RewriteRule /mywebsite/home index.php?uc=home [L]

I think this is more like this :
RewriteRule is relative to the RewriteBase, so if your .htacess is in /mywebsite/ folder :
RewriteBase /
RewriteRule /home index.php?uc=home [L]
this way it should work, let me know ;)

So... If this is not working, let's start by the beginning.
Find httpd.conf
LoadModule rewrite_module libexec/mod_rewrite.so and AddModule mod_rewrite.c should be in there, and without comment mark (#)
In your .htaccess, there is :
# The server must follow symbolic links (this can help in some apache versions)
Options +FollowSymlinks
# RewriteEngine activation
RewriteEngine on
# RewriteRule
RewriteRule ^home$ index.php?uc=home [L]
This configuration works on my apache 2.2.22.
The truth is that
/index.php?uc=home [L]
points on http://127.0.0.1/index.php
instead of http://127.0.0.1/mywebsite/index.php
because of the DocumentRoot property. On a real domain, or /w a virtualhost pointing on /mywebsite/, /index.php?uc=home [L] should work.
Keep in mind that RewriteRule is relative to the DocumentRoot and RewriteBase can't resolves this problem.

Related

Enable .htaccess in localhost server

I am trying to change the url of my webpage at localhost but i am unable to figure it out. I am using windows 7(64 bits).
I already uncomment the "LoadModule rewrite_module modules/mod_rewrite.so" and AllowOverride None to AllowOverride All.
I want to change my url "http://localhost/mywebsite/product_name.php?name=alfa" to something like that "http://localhost/product_name/alfa"
My .htaccess file code is below:
RewriteEngine on
RewriteBase /
RewriteRule ^([^/\.]+)/?$ product_name.php?name=$1 [L]"
my php file code is:
.....
Please help me I tried many changes in my htaccess file but could not find a solution
Change your php code to:
.....
Or add this rule:
RewriteCond %{THE_REQUEST} \ /+product_name\.php\?name=([^&\ ]+)
RewriteRule ^ /%1? [L,R]

.htaccess doesn't work on xampp (windows 7)

I'm setting my .htaccess file right now to use friendly urls (manually). But, when i go to the url the server shows me Error 404.
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
Rewriterule ^register$ register.php
I'm really sure that mod_rewrite is enabled because i see it when use phpinfo().
Even though mod-rewrite is enabled, by default it is not enabled for .htaccess files.
Hold Your Breath
Open xampp control panel
Stop Apache
Click the Config button on the Apache row, and select httpd.conf
In that file, search for something like xampp/htdocs">
A bit lower, you may see a line like this: # AllowOverride All. Remove the #, which is a comment
Alternately, search for AllowOverride All, make sure it is in the right section, and remove the comment #
Save the file
Restart Apache, say a prayer, cross your fingers and hold your breath
This listing may be old but is still relevant so to make it a little more secure it is probably best to add a few lines.
Deny from all
Allow from 127.0.0.1 ::1 localhost
Allow from .htaccess
Also as a side note .htaccess files slow the speed of the server so it would be best to refer to xampp documentation for best practices.
Hope it helps.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
if we want to remove index.php form url .First we create a .htaccess file on root directory of project with out any extension. And add this code in this file and so remove the index.php Application/config/config.php
Check in httpd.conf you tag, review this property
AllowOverride All
AllowOverride authorize use htaccess file.

Concrete5 project throws 404 on all pages except index.php

I just copied a concrete5 project over to my local box and am trying to get it running on localhost. I had permissions problems at the start so I just ran a sudo chmod 777 -R site which remedied that. I then had problems with clicking a link. Anything besides index.php would result in a 404. So I messed around with the htaccess file. It came in this state:
# Use PHP53 as default
AddHandler application/x-httpd-php53 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php53/lib
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
and I changed it to this:
# Use PHP53 as default
AddHandler application/x-httpd-php53 .php
<IfModule mod_suphp.c>
suPHP_ConfigPath /opt/php53/lib
</IfModule>
<Directory>
AllowOverride All
</Directory>
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}/index.php !-f
RewriteRule . index.php [L]
</IfModule>
Now, none of that helped. I decided to just disable pretty URLs in the database. I did that and most links work. It looks like some still don't (maybe the ones that are involved in a package. I don't know because I am picking up this project where someone left it). Bear in mind this all works perfectly on the live server at this time with the first .htaccess file I showed.
Any idea as to how to remedy this?
It does sound like you are having an issue with Pretty URLs. The ones that are still not working after you disabled it are likely do cached items like blocks. If you clear you cache your site will likely work without Pretty URLs turned on.
As for why Pretty URLs are not working, I would first make sure that mod_rewrite is enabled. Then you can try a couple of these for the rewrite rule.
RewriteRule ^(.*)$ index.php [L]
RewriteRule .* index.php [L]
Note: you can use the scripts from your admin login to update "pretty URLs". One caution would be is that if you use .htaccess for another purpose on your site.
Try removing the htaccess completely. Rather than deleting it, rename it. Then get into the dashboard directly at /index/dashboard/ , disable pretty urls, disable and clear the cache, and clear your browser cache.
(In general, always disable pretty urls and disable and clear the cache before cloning a site.)
Once everything is working without pretty urls, you can then start re-enabling.
I've just hit this one whilst trying out concrete5 on my home machine (linux/apache).
In my case, the problem appears to have been because I'd installed concrete5 two directory levels beneath the document root (/var/www/html). Initially, I just created the .htaccess file based on the values given when I enabled pretty urls, then hit the "page not found" problem (couldn't even log in.) Eventually, the penny dropped: I edited .htaccess and changed RewriteRule to point to the actual location of the concrete5 index.php relative to /var/www/html.
So in my case, concrete5 is installed into /var/www/html/playpen/public_html - so the new RewriteRule reads:
RewriteRule . playpen/public_html/index.php
and that appears to work.
Hope it helps someone ...

How do I redirect non-existant subdirectory in my index.php file, keeping the URL

I want to basically be able to goto, for example: www.example.com/my/folder/
where the subdirectories /my/folder/ don't exist, and have it redirect to index.php?path=/my/folder, while still keeping the original URL.
I hope this makes sense. I basically have no idea where to start with this. I'm guessing it's something with .htaccess, or http.conf or something, but I have no clue.
I basically want some direction on where to figure out how to do this, or some suggestions.
I always liked borrowing from the Wordpress .htaccess file myself
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This little bit of code will rewrite anything that is not a file and send it to your index.php file. You can then parse $_SERVER['REQUEST_URI'] for anything you need from the URL itself.
It depends on what web server you're running. If you're running Apache, then yes, it's in the .htaccess file or the VirtualHost file. In addition, mod_rewrite will need to be enabled on your Apache server for this to work.
sudo a2enmod mod_rewrite
sudo service apache2 restart
Other web servers will have it in different locations and require different commands.

Apache rewrite rule works on localhost but not on server

I have a site that I would like to use Apache's RewriteRule to rewrite URLs.
I want:
http://baileyseymour.com/index.php?p=home
to rewrite to
http://baileyseymour.com/p/home
I have AMPPS installed on my Mac and I added the following lines to httpd.conf and they work successfully:
RewriteEngine On
RewriteRule ^/p/(.*) /index.php?p=$1 [PT]
I'm trying to do the same but on my server.
And I have added the same apache code to /public_html/.htaccess but I get the error message below:
Not Found
The requested URL /p/home was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
The exact same code works on my localhost server. Why not on my website?
Can you check your remote server apache supports "AllowOverride All" ?
also try this way maybe it will help.
RewriteEngine On
RewriteRule ^p/(.*) /index.php?p=$1 [PT]
but you may have to modify $_GET['p'] properly. which will be sent only "home" part.
You need to remove the leading slash from the rewrite rule's pattern. URI's have their leading slash removed when the rewrite engine applies rules in an htaccess file.
RewriteEngine On
RewriteRule ^p/(.*) /index.php?p=$1 [PT]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.baileyseymour\.com
RewriteRule ^(.*)$ http://www.baileyseymour.com/$1 [R=301,L]
</IfModule>
.htaccess is the right place to put them and that file should be in the same directory as your default home page.

Categories