I have just made a central dynamic script to replace a messy folder full of static files. However, I would like to preserve the old URL's without having to delete those files. Let me give you an example:
I have the following files:
/oldpages/projekt1/index.html
/oldpages/projekt2/index.html
/oldpages/projekt3/index.html
The actual new urls are:
/newscript/script.php?name=projekt1
/newscript/script.php?name=projekt2
/newscript/script.php?name=projekt3
The rewrite rule is:
Options -MultiViews -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^oldpages/([A-Za-z0-9_\-]+)/(index.html)?$ /newscript/script.php?name=$1 [L,QSA]
However, whenever I try to access http://mydomain.com/oldpages/projekt3/index.html it just keeps giving back the old files. After googling, everyone said that multiviews may be the culprit, but apparently, that's not fixing it.
The rule works if the directory doesn't exist on the server, the following works perfectly:
Options -MultiViews -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^newpages/([A-Za-z0-9_\-]+)/(index.html)?$ /newscript/script.php?name=$1 [L,QSA]
And http://mydomain.com/newpages/projekt3/index.html gets the right page.
What am I doing wrong?
Any help would be greatly appreciated.
If a .htaccess in /oldpages has RewriteEngine On, that overrides all rules in the .htaccess in /.
Related
Hey I am trying to link to a subdirectory and have index.php in that directory load, but it is returning a 404 not found error. The file structure is this:
| index.php
| .htaccess
| subfolder
| index.php
| about.php
When I go to mysite.com/subfolder, I want the index.php there to load. I know the problem is with my .htaccess file because when I remove it the URL works. Here is the code in .htaccess:
Options +MultiViews
# Remove file extensions from page names
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
# Disable Index Listing
Options -Indexes
My guess is that because I'm removing file extensions, the server is looking for mysite/subfolder.php and can't find it so it 404s. I'm new to .htaccess files, however, and they're still very cryptic to me. Searching online has a lot of code but doesn't explain how anything works. Any ideas on how to fix this issue and why the fix works would be helpful!
If you are enabling MultiViews option then you don't need a rewrite rule to handle extensions.
Just keep these lines in your .htaccess:
Options +MultiViews
DirectorySlash On
DirectoryIndex index.php
And remove everything else. Then test with mysite.com/subfolder/ URL
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 ...
Looking to re write a url in WAMP. I have AllowOverride Al (conf file). The mod rewrite modules is loaded. I am working on localhost
What i want to acheive is that on login the user gets redirected
localhost/propcms/xxxxxxx/
the actual address is
localhost/propcms/status.php?id=xxxxxxx
the .htaccess file has the following (and is located in localhost/propcms/ )
Options +FollowSymlinks
RewriteEngine on
RewriteBase /propcms/
RewriteRule ^propcms/([^/]*)/$ /propcms/status.php?id=$1 [L]
this is what i get....The requested URL /propcms/test121/ was not found on this server.
any ideas ??
Since you are specifying a rewritebase, you should not include it in your rewrite rule:
Try this snippet :
Options +FollowSymlinks
RewriteEngine on
RewriteBase /propcms/
RewriteRule ^([^/]*)/$ /propcms/status.php?id=$1 [L]
i'm having some mod_rewrite problems. I am working on a rewrite simple rewrite tool that should help me with my website. but i don't know where is the problem
this is my .htaccess file:
RewriteEngine on
RewriteBase /
RewriteRule ^text\/$ text.php [L,NC]
and my phpinfo() says that i have my mod_rewrite loaded
also i have a apache hadler: AllowOverride On
so I don't know why this isn't working... can anyone tell me what else could be the problem ?
You need to add the following at the top of your .htaccess file
Options +FollowSymlinks
Also, what rewrites do is allow you to go to
http://www.mydomain.com/text
and see the content that would be generated if you actually went to
http://www.mydomain.com/text.php
rather than the other way around. So the rewrite rules are basically
RewriteRule <what-I-type-in-my-address-bar> <what-page-I-see>
I found out I could make clean urls with mod_rewrite. I managed to make pages like /home.php viewable by visiting /home (without .php).
Now, I'd like to turn view_album.php?album_id=23 into album/23
This is the code I use, but sadly it's not working:
Options SymLinksIfOwnerMatch MultiViews
RewriteEngine On
RewriteBase /beta/
RewriteRule ^album/(.*)/ view_album.php?album_id=$1
Thanks in advance.
use
RewriteEngine On
RewriteBase /beta/
RewriteRule ^album/([0-9]*)$ view_album.php?album_id=$1
and make sure you only rewrite if a noting or a number follows album/, so your can access your images, which may be in a folder named album.