mod_rewrite short url doesn't work

Discuss practical ways rearrange URLs using mod_rewrite.

mod_rewrite short url doesn't work

Postby rewriteme » Mon Nov 10, 2008 3:49 pm

Hi,
I'm trying get my short url to work but no luck so far. I'm on an Apache 2.2.3 and Centos 5.2, php 5 and mysql 5.

Here's what I have:

.htacess file:
ErrorDocument 403 /index.php?do=/public/error/403/
ErrorDocument 404 /index.php?do=/public/error/404/

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/design/.*
RewriteCond %{REQUEST_URI} !^/favicon.ico$
RewriteCond %{REQUEST_URI} !^/file/.*
RewriteCond %{REQUEST_URI} !^/include/.*
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{REQUEST_URI} !^/plugins/.*
RewriteCond %{REQUEST_URI} !^/robots.txt$
RewriteCond %{REQUEST_URI} !^/site/.*
RewriteRule ^index.php(/.*)$ /index.php?do=$1 [L]

RewriteCond %{REQUEST_URI} !^/design/.*
RewriteCond %{REQUEST_URI} !^/favicon.ico$
RewriteCond %{REQUEST_URI} !^/file/.*
RewriteCond %{REQUEST_URI} !^/include/.*
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{REQUEST_URI} !^/plugins/.*
RewriteCond %{REQUEST_URI} !^/robots.txt$
RewriteCond %{REQUEST_URI} !^/site/.*
RewriteRule ^(.*)$ /index.php?do=/$1 [L]

server.sett.php file:
$_CONF['rewrite_engine'] = true;
$_CONF['path_translated'] = true;

httpd.conf file:

# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the "default" to be a very restrictive set of
# features.

RewriteEngine On

<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
Options +FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</Directory>


With the above settings, here's what happen:
1) Only the home page loads up
2) all other pages/links doesn't work. I get a 404 error message. Here are some of the messages:

Not Found

The requested URL /login/ was not found on this server.
Apache/2.2.3 (CentOS) Server at 192.168.10.112 Port 80

Not Found

The requested URL /poll/ was not found on this server.
Apache/2.2.3 (CentOS) Server at 192.168.10.112 Port 80

Not Found

The requested URL /forum/ was not found on this server.
Apache/2.2.3 (CentOS) Server at 192.168.10.112 Port 80



However, when I change the server.sett.php to:

$_CONF['rewrite_engine'] = false;
$_CONF['path_translated'] = false;

All pages work except no short url. The short url just simply doesn't work.

What do you suggest?
rewriteme
 
Posts: 6
Joined: Mon Nov 10, 2008 1:35 pm

Postby richardk » Wed Nov 12, 2008 12:27 pm

The mod_rewrite you have can be shortened to
Code: Select all
ErrorDocument 403 /index.php?do=/public/error/403/
ErrorDocument 404 /index.php?do=/public/error/404/
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(design|file|include|plugins|site)(/.*)?$
RewriteCond %{REQUEST_URI} !^/(index\.php|robots\.txt|favicon\.ico)$
RewriteRule ^index.php(/.*)$ /index.php?do=$1 [L]

RewriteCond %{REQUEST_URI} !^/(design|file|include|plugins|site)(/.*)?$
RewriteCond %{REQUEST_URI} !^/(index\.php|robots\.txt|favicon\.ico)$
RewriteRule ^(.*)$ /index.php?do=/$1 [L]


rewriteme wrote:
FAQ wrote:How to check if mod_rewrite is enabled.

Put the following mod_rewrite in a .htaccess file in your document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule Google http://www.google.com/? [NC,R,L]

Now go to http://example.com/Google (where example.com is your domain or IP address). If you are redirected to Google, mod_rewrite should be working OK.

Hi. I've done the above and yet I was not redirected to Google. I think this might be the source of my problem. The mod_rewrite doesn't work. The mod_rewrite is commented out. I have the rewrite engine in .htacess turned to on. The Allowoveride is set to All in httpd.conf. Can someone help out please? Thanks.

Do you have a LoadModule line for mod_rewrite?
Do you have the following line?
Code: Select all
AccessFileName .htaccess

Does the mod_rewrite test work if you put it in your httpd.conf file and restart Apache?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

mod_rewrite short url doesn't work

Postby rewriteme » Wed Nov 12, 2008 1:17 pm

Hi Richard,

Do you have a LoadModule line for mod_rewrite?


Yep, this is just 3 of the modules in the httpd.conf file.
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so

Do you have the following line?
Code:
AccessFileName .htaccess


Yes I do have the above code in the httpd.conf file.

Does the mod_rewrite test work if you put it in your httpd.conf file and restart Apache?

No, it doesn't. I typed 192.168.1.1/google and it gives me this error msg:

Not Found

The requested URL /google was not found on this server.
Apache/2.2.3 (CentOS) Server at 192.168.10.112 Port 80

Is my apache messed up or something?
rewriteme
 
Posts: 6
Joined: Mon Nov 10, 2008 1:35 pm

.htaccess file not being read?

Postby rewriteme » Wed Nov 12, 2008 1:54 pm

Richard,

Do you think my .htacess file is not being read? Perhaps that is why the mod_rewrite is not working? If so, how can I get apache to read the .htaccess file? Perhaps we can try that too.
rewriteme
 
Posts: 6
Joined: Mon Nov 10, 2008 1:35 pm

full access to httpd.conf file

Postby rewriteme » Wed Nov 12, 2008 2:01 pm

Rich,
I just realized that I have full access to my httpd.conf file. So I don't have to use the .htaccess file then right? If so, how can I get my short url to work from the httpd.conf file?
rewriteme
 
Posts: 6
Joined: Mon Nov 10, 2008 1:35 pm

Postby richardk » Wed Nov 12, 2008 2:05 pm

I think i will need to see all your Apache configuration. You can email it to me at removed.

Do you think my .htacess file is not being read? Perhaps that is why the mod_rewrite is not working? If so, how can I get apache to read the .htaccess file? Perhaps we can try that too.

No, because the mod_rewrite should work in the httpd.conf file. But to check, if you put a random word in the .htaccess file (on it's own line, no #s), do you get a 500 error? You should get a 500 error if the .htaccess is processed.

You can also try this in your httpd.conf file to make sure that is the one being used. Apache will not (re)start if there is bad configuration.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby rewriteme » Wed Nov 12, 2008 3:39 pm

Hi Rich,
I emailed you already and also stating that I didn't get any 500 error messages when I add junk text to the .htaccess file. I also renamed the .htacess to something else and my site still loads up fine.

Additionally, I added some junk texts in the httpd.conf file, restart apache and I didn't get any error messages.

I sent you my httpd.conf file. I hope you can find the problem.

Thanks.
rewriteme
 
Posts: 6
Joined: Mon Nov 10, 2008 1:35 pm

Postby rewriteme » Wed Nov 12, 2008 4:04 pm

Correction. Adding junk text in the httpd.conf file did caused an error. In fact, I don't think apache even started. So the httpd.conf is being read.
rewriteme
 
Posts: 6
Joined: Mon Nov 10, 2008 1:35 pm


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 20 guests

cron