I have this code:
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ראשי$ index.php?page=main [L,QSA,NC]
RewriteRule ^ניהול גלריות$ index.php?page=galleries [L,QSA,NC]
RewriteRule ^ניהול דפים$ index.php?page=pages [L,QSA,NC]
RewriteRule ^ניהול משתמשים$ index.php?page=users [L,QSA,NC]
RewriteRule ^הגדרות כלליות$ index.php?page=settings [L,QSA,NC]
RewriteRule ^דיווחים$ index.php?page=reports [L,QSA,NC]
</IfModule>
It's making an 500 internal server error, if I only put the lines with one word like "דיווחים" it works but when I add those with two words like "ניהול דפים" not working.
How can you fix it? (maybe the problam is in the space between the 2 words?)
The language isn't the problem even if I use English it's not working.
My address is like /ניהול דפים
What you are writing there essentially are regular expressions. You might want to try using a regular expression meta character to indicate the presence of a space.
Why don't you try something like this -
RewriteRule ^ברזילאי\sדן$ index.php?page=galleries [L,QSA,NC]
The \s indicates whitespace.
mod_rewrite supports logging, so you could could add this to get more details:
RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 2
Also check apache's error_log, as it usually writes something on a 500 error.
Related
I am trying to write SEO friendly usls using Apache Mod-Rewrite.
My URLs are something like this.
index.php?p=edit-profile
index.php?p=edit-profile&id=3
index.php?p=edit-profile&id=3&city=sydney
index.php?p=edit-profile&id=3&city=sydney&name=some example text
This is how I tried it.
RewriteRule ^([\w-]+)/?$ index.php?p=$1 [L,QSA,NC]
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?p=$1&id=$2 [L,QSA,NC]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ index.php?p=$1&id=$2&city=$3 [L,QSA,NC]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/([\w-]+)/?$ index.php?p=$1&id=$2&city=$3&name=$4 [L,QSA,NC]
Here, first, second and third rules are working for me. But my problem is If I have a string with spaces for fourth variable my forth rule is not working. And also if I have a single word for forth one again it doesn't work.
Can anybody tell me how I fix this problem. Is there a way to replace these spaces with hyphens?
Thank you.
You can include space in your character class:
RewriteRule ^([\w-]+)/?$ index.php?p=$1 [L,QSA,NC]
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?p=$1&id=$2 [L,QSA,NC]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/?$ index.php?p=$1&id=$2&city=$3 [L,QSA,NC]
RewriteRule ^([\w-]+)/([\w-]+)/([\w-]+)/([\s\w-]+)/?$ index.php?p=$1&id=$2&city=$3&name=$4 [L,QSA,NC]
I have a htaccess setup like so:
RewriteRule ^([A-Za-z_]+)$ profile.php?name=$1 [NC,B,QSA]
it works fine however it doesn't work when the parameter has a number in it.
also is it possible to allow periods and commas?
What can I change?
Change the regex:
RewriteRule ^([0-9A-Za-z_]+)$ profile.php?name=$1 [L,QSA]
OR even better
RewriteRule ^(\w+)/?$ profile.php?name=$1 [QSA,L]
Since \w is same as [0-9A-Za-z_]
OP's comment:
is there a way to let it use periods and commas as well?
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w,.]+)/?$ profile.php?name=$1 [QSA,L]
I am trying to apply mod rewrites to my URL to make it nicer but I am getting caught up in all the confusion of this subject.
Please could you help me out with the following examples of what I want to do :
I want to attach any variable from the root of my site into the lyprofile.php page
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{THE_REQUEST} /(.*)
RewriteRule /(.*) lyprofile.php?us=$1
I want a url such as profile/settings to go to lysettings.php
# Turn mod_rewrite on
RewriteEngine On
RewriteCond %{THE_REQUEST} /profile/settings
RewriteRule /profile/settings lysettings.php
These two examples if working should help me to work out all my other URL's, but I can't get these to work.
Also do you need an absolute URL, as I'm working on my local machine and an absolute URL would just cause a lot of hassle. Just in case my absolute URL is http://localhost/Linku2.5/
You generally want to go from the most specific rules to the least specific. Of the two things that you want to do, the first is the least specific, as (.*) can be anything. So we have to start with the much more specific and less arbitrary /profile/settings.
If these rules are in your htaccess file (in your case, in the Link2.5 directory), you don't want a leading slash, so simply:
# you only need to turn on once
RewriteEngine On
# Don't need absolute URLs, but you may need this line:
RewriteBase /Link2.5/
RewriteRule ^profile/settings lysettings.php [L]
Then, because your other rule is so general, you need to add some conditions so that you don't cause an infinite loop (the rewrite engine will continue to loop until the URI stops changing):
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ lyprofile.php?us=$1 [L,QSA]
If you know your "us" variable can only be numbers or letters, you can make the line with the rule a bit more specific:
RewriteRule ^([A-Za-z0-9]+)$ lyprofile.php?us=$1 [L,QSA]
etc.
Can you check this in vhosts config?
# Turn mod_rewrite on
RewriteEngine On
RewriteRule lyprofile\.php - [L]
RewriteCond %{REQUEST_URI} /(.*)
RewriteRule /(.*) lyprofile.php?us=$1 [L]
RewriteCond %{REQUEST_URI} /profile/settings
RewriteRule /profile/settings lysettings.php [L]
I want the following url:
http://localhost/new/post?url=sample-post-one
to Look Like this via htaccess mod_rewrite:
http://localhost/new/post/sample-post-one/
This might be a question asked already or a similar one but I have been trying to figure it out since a couple of hours and did not get to a solution.
Any help will be highly appreciated. Thanks!
Update
Here's what I've tried
<Files .htaccess,.svn> order allow,deny deny from all </Files>
Options +FollowSymlinks
# For Removing .php extension from files
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
# Rewrite rule
RewriteRule ^post/([a-zA-Z0-9_-]+)/?$ post?url=$1 [L]
This should work :
RewriteEngine on
RewriteRule ^post/([^/.]+)/?$ post?url=$1 [L]
Or better ...
RewriteEngine on
RewriteRule ^post/([a-zA-Z0-9_-]+)/?$ post?url=$1 [L]
By the way, you should have a look to guides like this one.
You can use below code:
http://localhost/new/post?url=sample-post-one
RewriteRule ^post/([0-9]+)/?$ post?url=$1 [NC,L] # Handle post requests
and to get more information you can refer to this
Basically we're capturing the bit for the last folder. The rest can be hard coded. Also you should delete the competing rule. ^ indicates beginning of string. $ is the end of the string. If you use both of those characters everything has to literally match except for the bits where we're using REGEX patterns for matching. Also everything is case sensitive.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^new/post/([^/]+)/?$ new/post?url=$1
If you know that you're only going to allow letters, numbers, periods, and hyphens, then you can do this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^new/post/([^A-Za-z0-9.-]+)/?$ new/post?url=$1
If for some reason you're including new/post and post is really your document root it should look like this:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^A-Za-z0-9.-]+)/?$ ?url=$1
Apache is a well documented application. They provide an excellent resource with hundreds of examples on their site with explanations of each in the mod_rewrite documentation.
My .htaccess:
RewriteEngine On
CheckCaseOnly On
CheckSpelling On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^Blog/(.*?)$ /Me/profile.php?username=$1 [QSA,L]
The problem is, when the URL is like this, it works:
localhost/Me/Blog/ExampleUser
But it doesn't work when it is like this (notice the 'b' in 'Blog' is in lowercase?):
localhost/Me/blog/ExampleUser
I'm running it on the new version of XAMPP. It is wierd its not working even though I have the mod_speling.so on the PHP config.
What is the problem?
Use of the [NC] flag causes the RewriteRule to be matched in a case-insensitive manner. That is, it doesn't care whether letters appear as upper-case or lower-case in the matched URI.
Try [QSA,L,NC] instead, so the comparison is made in a case-insensitive manner
the problem is that rewrite rules ARE case sensitive. So your Rewrite rule should be:
RewriteRule ^[Bb]log/(.*?)$ /Me/profile.php?username=$1 [QSA,L]
and voila you are fixed.
mod_speling.so has NOTHING to do with this.